107 lines
3.1 KiB
Dart
107 lines
3.1 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:file_selector/file_selector.dart';
|
|
import 'dart:io';
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
String? _targetImagePath;
|
|
String? _tileImagesDirectoryPath;
|
|
|
|
Future<void> _pickTargetImage() async {
|
|
const XTypeGroup typeGroup = XTypeGroup(
|
|
label: 'images',
|
|
extensions: <String>['jpg', 'png', 'jpeg', 'webp'],
|
|
);
|
|
final XFile? file = await openFile(
|
|
acceptedTypeGroups: <XTypeGroup>[typeGroup],
|
|
);
|
|
|
|
if (file != null) {
|
|
setState(() {
|
|
_targetImagePath = file.path;
|
|
});
|
|
if (kDebugMode) {
|
|
print('Selected Target Image: $_targetImagePath');
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _pickTileImagesDirectory() async {
|
|
final String? directoryPath = await getDirectoryPath();
|
|
|
|
if (directoryPath != null) {
|
|
setState(() {
|
|
_tileImagesDirectoryPath = directoryPath;
|
|
});
|
|
if (kDebugMode) {
|
|
print('Selected Tile Images Directory: $_tileImagesDirectoryPath');
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Photo Mosaic Generator'),
|
|
centerTitle: true,
|
|
),
|
|
body: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
ElevatedButton(
|
|
onPressed: _pickTargetImage,
|
|
child: const Text('Select Target Image'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
_targetImagePath == null
|
|
? 'No target image selected.'
|
|
: 'Target Image: ${_targetImagePath!.split('/').last}',
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 30),
|
|
|
|
ElevatedButton(
|
|
onPressed: _pickTileImagesDirectory,
|
|
child: const Text('Select Tile Images Folder'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
_tileImagesDirectoryPath == null
|
|
? 'No tile images folder selected.'
|
|
: 'Tile Images Folder: ${_tileImagesDirectoryPath!.split('/').last}',
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 50),
|
|
|
|
ElevatedButton(
|
|
onPressed:
|
|
(_targetImagePath != null &&
|
|
_tileImagesDirectoryPath != null)
|
|
? () {
|
|
if (kDebugMode) {
|
|
print('Generate Mosaic button pressed!');
|
|
}
|
|
}
|
|
: null,
|
|
child: const Text('Generate Mosaic'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|