WIP: Turn advent of code into flutter app #1

Draft
bearmine wants to merge 8 commits from turn-into-flutter-app into main
4 changed files with 62 additions and 9 deletions
Showing only changes of commit e92c62270c - Show all commits

3
devtools_options.yaml Normal file
View File

@@ -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:

View File

@@ -1,42 +1,63 @@
import "util.dart";
import 'package:adventofcode2025/main.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import "days_enum.dart";
Future<void> selectFile() async { Future<String?> selectFile() async {
print("Button Pushed"); debugLog("selectFile Button pushed");
FilePickerResult? result = await FilePicker.platform.pickFiles(); FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) { if (result != null) {
//File file = File(result.files.single.path!); //File file = File(result.files.single.path!);
print(result.files.single.path!); debugLog(result.files.single.path!);
return result.files.single.path;
} else { } else {
// User canceled the picker return null;
} }
} }
class DayPage extends StatelessWidget { class DayPage extends StatelessWidget {
const DayPage({super.key}); final AdventOfCodeDays day;
const DayPage(this.day, {super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var state = context.watch<MyAppState>();
return Center( return Center(
child: Column( child: Column(
children: [ children: [
Row( Row(
children: [ children: [
TextButton(onPressed: selectFile, child: Text("Select Input")), TextButton(
onPressed: () async {
var selectedFile = await selectFile();
state.setSelectedFile(day, selectedFile);
},
child: Text("Select Input"),
),
SizedBox( SizedBox(
width: 300, width: 300,
child: TextField( child: TextField(
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
hintText: 'Input File Path', //hintText: 'Input File Path',
hintText: state.getSelectedFile(day),
), ),
), ),
), ),
], ],
), ),
Row( Row(
children: [TextButton(onPressed: selectFile, child: Text("Run"))], children: [
TextButton(
onPressed: () async {
debugLog("RUNNING $day!");
},
child: Text("Run"),
),
],
), ),
Expanded( Expanded(
child: Row( child: Row(

View File

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'days_enum.dart'; import 'days_enum.dart';
import 'day_page.dart'; import 'day_page.dart';
import "util.dart";
void main() { void main() {
runApp(MyApp()); runApp(MyApp());
@@ -28,7 +29,28 @@ class MyApp extends StatelessWidget {
} }
} }
class DayPageState {
String? selectedFile;
}
class MyAppState extends ChangeNotifier { 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 { class MyHomePage extends StatefulWidget {
@@ -56,7 +78,7 @@ class _MyHomePageState extends State<MyHomePage> {
} }
var colorScheme = Theme.of(context).colorScheme; var colorScheme = Theme.of(context).colorScheme;
Widget page = DayPage(); Widget page = DayPage(AdventOfCodeDays.day1);
// The container for the current page, with its background color // The container for the current page, with its background color
// and subtle switching animation. // and subtle switching animation.

7
lib/util.dart Normal file
View File

@@ -0,0 +1,7 @@
import 'package:flutter/foundation.dart';
void debugLog(String? msg, {int? wrapWidth}) {
if (kDebugMode) {
debugPrint(msg, wrapWidth: wrapWidth);
}
}