🎉 Initial Commit
This commit is contained in:
50
lib/main.dart
Normal file
50
lib/main.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'package:dietary_guard/screens/query.dart';
|
||||
import 'package:dietary_guard/screens/settings.dart';
|
||||
import 'package:dietary_guard/shells/nav_shell.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
final router = GoRouter(routes: [
|
||||
ShellRoute(
|
||||
builder: (context, state, child) => NavShell(child: child),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: "/",
|
||||
name: "query",
|
||||
builder: (context, state) => const QueryScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: "/settings",
|
||||
name: "settings",
|
||||
builder: (context, state) => const SettingsScreen(),
|
||||
),
|
||||
],
|
||||
),
|
||||
]);
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetMaterialApp.router(
|
||||
title: 'DietaryGuard',
|
||||
routerDelegate: router.routerDelegate,
|
||||
routeInformationParser: router.routeInformationParser,
|
||||
routeInformationProvider: router.routeInformationProvider,
|
||||
backButtonDispatcher: router.backButtonDispatcher,
|
||||
locale: Get.deviceLocale,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.green,
|
||||
),
|
||||
useMaterial3: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
10
lib/screens/query.dart
Normal file
10
lib/screens/query.dart
Normal file
@ -0,0 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class QueryScreen extends StatelessWidget {
|
||||
const QueryScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SizedBox();
|
||||
}
|
||||
}
|
10
lib/screens/settings.dart
Normal file
10
lib/screens/settings.dart
Normal file
@ -0,0 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
48
lib/shells/nav_shell.dart
Normal file
48
lib/shells/nav_shell.dart
Normal file
@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class Destination {
|
||||
const Destination(this.title, this.page, this.icon);
|
||||
final String title;
|
||||
final String page;
|
||||
final IconData icon;
|
||||
}
|
||||
|
||||
class NavShell extends StatefulWidget {
|
||||
final Widget child;
|
||||
|
||||
const NavShell({super.key, required this.child});
|
||||
|
||||
@override
|
||||
State<NavShell> createState() => _NavShellState();
|
||||
}
|
||||
|
||||
class _NavShellState extends State<NavShell> {
|
||||
int _focusDestination = 0;
|
||||
|
||||
final List<Destination> _allDestinations = <Destination>[
|
||||
const Destination('Query', 'query', Icons.search),
|
||||
const Destination('Settings', 'settings', Icons.settings)
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: widget.child,
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
showUnselectedLabels: false,
|
||||
currentIndex: _focusDestination,
|
||||
items: _allDestinations
|
||||
.map((x) => BottomNavigationBarItem(
|
||||
icon: Icon(x.icon),
|
||||
label: x.title,
|
||||
))
|
||||
.toList(),
|
||||
onTap: (value) {
|
||||
GoRouter.of(context).goNamed(_allDestinations[value].page);
|
||||
setState(() => _focusDestination = value);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user