diff --git a/devtools_options.yaml b/devtools_options.yaml new file mode 100644 index 0000000..fa0b357 --- /dev/null +++ b/devtools_options.yaml @@ -0,0 +1,3 @@ +description: This file stores settings for Dart & Flutter DevTools. +documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states +extensions: diff --git a/lib/day_page.dart b/lib/day_page.dart index 232021c..d3892c3 100644 --- a/lib/day_page.dart +++ b/lib/day_page.dart @@ -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 selectFile() async { - print("Button Pushed"); +Future 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(); 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( diff --git a/lib/main.dart b/lib/main.dart index ccd22ca..b1d9fe6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 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 { } 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. diff --git a/lib/util.dart b/lib/util.dart new file mode 100644 index 0000000..1c73460 --- /dev/null +++ b/lib/util.dart @@ -0,0 +1,7 @@ +import 'package:flutter/foundation.dart'; + +void debugLog(String? msg, {int? wrapWidth}) { + if (kDebugMode) { + debugPrint(msg, wrapWidth: wrapWidth); + } +} \ No newline at end of file