Scaffold out initial state management
This commit is contained in:
@@ -1,42 +1,63 @@
|
||||
import "util.dart";
|
||||
import 'package:adventofcode2025/main.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import "days_enum.dart";
|
||||
|
||||
Future<void> selectFile() async {
|
||||
print("Button Pushed");
|
||||
Future<String?> selectFile() async {
|
||||
debugLog("selectFile Button pushed");
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles();
|
||||
|
||||
if (result != null) {
|
||||
//File file = File(result.files.single.path!);
|
||||
print(result.files.single.path!);
|
||||
debugLog(result.files.single.path!);
|
||||
return result.files.single.path;
|
||||
} else {
|
||||
// User canceled the picker
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class DayPage extends StatelessWidget {
|
||||
const DayPage({super.key});
|
||||
final AdventOfCodeDays day;
|
||||
const DayPage(this.day, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var state = context.watch<MyAppState>();
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
TextButton(onPressed: selectFile, child: Text("Select Input")),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
var selectedFile = await selectFile();
|
||||
state.setSelectedFile(day, selectedFile);
|
||||
},
|
||||
child: Text("Select Input"),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
hintText: 'Input File Path',
|
||||
//hintText: 'Input File Path',
|
||||
hintText: state.getSelectedFile(day),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [TextButton(onPressed: selectFile, child: Text("Run"))],
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
debugLog("RUNNING $day!");
|
||||
},
|
||||
child: Text("Run"),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Row(
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'days_enum.dart';
|
||||
import 'day_page.dart';
|
||||
import "util.dart";
|
||||
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
@@ -28,7 +29,28 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class DayPageState {
|
||||
String? selectedFile;
|
||||
}
|
||||
|
||||
class MyAppState extends ChangeNotifier {
|
||||
Map<AdventOfCodeDays, DayPageState> dayPageState = {};
|
||||
|
||||
MyAppState() {
|
||||
for (var day in AdventOfCodeDays.values) {
|
||||
dayPageState[day] = DayPageState();
|
||||
}
|
||||
}
|
||||
|
||||
String? getSelectedFile(AdventOfCodeDays day) {
|
||||
return dayPageState[day]?.selectedFile;
|
||||
}
|
||||
|
||||
void setSelectedFile(AdventOfCodeDays day, String? file) {
|
||||
debugLog("setSelectedFile called on $day");
|
||||
dayPageState[day]?.selectedFile = file;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
@@ -56,7 +78,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
}
|
||||
var colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
Widget page = DayPage();
|
||||
Widget page = DayPage(AdventOfCodeDays.day1);
|
||||
|
||||
// The container for the current page, with its background color
|
||||
// and subtle switching animation.
|
||||
|
||||
7
lib/util.dart
Normal file
7
lib/util.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
void debugLog(String? msg, {int? wrapWidth}) {
|
||||
if (kDebugMode) {
|
||||
debugPrint(msg, wrapWidth: wrapWidth);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user