diff --git a/lib/home_page.dart b/lib/home_page.dart new file mode 100644 index 0000000..41779cd --- /dev/null +++ b/lib/home_page.dart @@ -0,0 +1,106 @@ +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 createState() => _HomePageState(); +} + +class _HomePageState extends State { + String? _targetImagePath; + String? _tileImagesDirectoryPath; + + Future _pickTargetImage() async { + const XTypeGroup typeGroup = XTypeGroup( + label: 'images', + extensions: ['jpg', 'png', 'jpeg', 'webp'], + ); + final XFile? file = await openFile( + acceptedTypeGroups: [typeGroup], + ); + + if (file != null) { + setState(() { + _targetImagePath = file.path; + }); + if (kDebugMode) { + print('Selected Target Image: $_targetImagePath'); + } + } + } + + Future _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: [ + 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'), + ), + ], + ), + ), + ), + ); + } +}