Files
adventofcode2025/lib/main.dart
2026-02-21 15:56:39 -06:00

96 lines
2.4 KiB
Dart

// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'days_enum.dart';
import 'day_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => MyAppState(),
child: MaterialApp(
title: 'Advent of Code 2025',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
),
home: MyHomePage(),
),
);
}
}
class MyAppState extends ChangeNotifier {
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var selectedIndex = 0;
@override
Widget build(BuildContext context) {
// Manage days and create items list of a pages.
final days = [AdventOfCodeDays.day1, AdventOfCodeDays.day2];
List<NavigationRailDestination> dayItems = [];
for (var day in days) {
dayItems.add(
NavigationRailDestination(
icon: Icon(Icons.arrow_forward_ios),
label: Text(day.title),
),
);
}
var colorScheme = Theme.of(context).colorScheme;
Widget page = DayPage();
// The container for the current page, with its background color
// and subtle switching animation.
var mainArea = ColoredBox(
color: colorScheme.surfaceContainerHighest,
child: AnimatedSwitcher(
duration: Duration(milliseconds: 200),
child: page,
),
);
return Scaffold(
body: LayoutBuilder(
builder: (context, constraints) {
return Row(
children: [
SafeArea(
child: NavigationRail(
extended: constraints.maxWidth >= 600,
destinations: dayItems,
selectedIndex: selectedIndex,
onDestinationSelected: (value) {
setState(() {
selectedIndex = value;
});
},
),
),
Expanded(child: mainArea),
],
);
},
),
);
}
}