Added: lib/home_page.dart

This commit is contained in:
Hadi Mottale 2025-07-14 11:18:06 +03:30
parent 7c0b41c9f7
commit 1b2381d33c
1 changed files with 106 additions and 0 deletions

106
lib/home_page.dart Normal file
View File

@ -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<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'),
),
],
),
),
),
);
}
}