rluv_client/lib/main.dart

151 lines
4.3 KiB
Dart
Raw Normal View History

2023-07-15 17:23:27 -06:00
import 'package:flutter/material.dart';
2023-07-19 02:16:13 -06:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2023-07-22 21:29:32 -06:00
import 'package:helpers/helpers/misc_build/build_media.dart';
2023-07-19 02:16:13 -06:00
import 'package:rluv/features/budget/screens/budget_overview.dart';
2023-07-22 21:29:32 -06:00
import 'package:rluv/features/notes/screens/notes_screen.dart';
import 'package:rluv/features/settings/screens/settings_screen.dart';
2023-07-19 02:16:13 -06:00
import 'package:rluv/global/styles.dart';
2023-07-22 21:29:32 -06:00
import 'package:rluv/global/utils.dart';
import 'package:rluv/global/widgets/drawer_button.dart';
2023-07-15 17:23:27 -06:00
2023-07-22 21:29:32 -06:00
import 'global/store.dart';
void main() async {
final _ = Store().prefs;
2023-07-15 17:23:27 -06:00
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
2023-07-19 02:16:13 -06:00
return ProviderScope(
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const Home(),
2023-07-15 17:23:27 -06:00
),
);
}
}
2023-07-19 02:16:13 -06:00
class Home extends ConsumerStatefulWidget {
const Home({super.key});
2023-07-15 17:23:27 -06:00
@override
2023-07-19 02:16:13 -06:00
ConsumerState<Home> createState() => _HomeState();
2023-07-15 17:23:27 -06:00
}
2023-07-19 02:16:13 -06:00
class _HomeState extends ConsumerState<Home> {
2023-07-22 21:29:32 -06:00
Map<String, dynamic> initData = {};
final drawerColors = Styles.curatedColors;
@override
void initState() {
setDevicePortraitOrientation();
super.initState();
}
2023-07-15 17:23:27 -06:00
@override
Widget build(BuildContext context) {
2023-07-22 21:29:32 -06:00
if (ref.watch(currentHomePageProvider).toString() ==
"BudgetOverviewScreen") {
initData = {};
}
2023-07-15 17:23:27 -06:00
return Scaffold(
2023-07-22 21:29:32 -06:00
key: ref.read(scaffoldKeyProvider),
2023-07-19 02:16:13 -06:00
resizeToAvoidBottomInset: false,
2023-07-22 21:29:32 -06:00
drawer: Drawer(
2023-07-19 02:16:13 -06:00
backgroundColor: Styles.purpleNurple,
2023-07-22 21:29:32 -06:00
child: SafeArea(
child: Column(
children: [
SizedBox(height: BuildMedia(context).height * 0.15),
CuteDrawerButton(
text: 'Budget',
color: drawerColors[4],
onPressed: () {
if (ref.read(currentHomePageProvider).toString() !=
"BudgetOverviewScreen") {
ref.read(currentHomePageProvider.notifier).state =
BudgetOverviewScreen(initialData: initData);
}
toggleDrawer();
},
),
CuteDrawerButton(
text: 'Notes',
color: drawerColors[5],
onPressed: () {
if (ref.read(currentHomePageProvider).toString() !=
"SharedNotesScreen") {
ref.read(currentHomePageProvider.notifier).state =
SharedNotesScreen(initialData: initData);
}
toggleDrawer();
},
),
const Spacer(),
CuteDrawerButton(
text: 'Settings',
color: drawerColors[0],
onPressed: () {
if (ref.read(currentHomePageProvider).toString() !=
"SettingsScreen") {
ref.read(currentHomePageProvider.notifier).state =
const SettingsScreen();
}
toggleDrawer();
},
),
const SizedBox(height: 24),
],
),
),
2023-07-15 17:23:27 -06:00
),
2023-07-19 02:16:13 -06:00
appBar: AppBar(
backgroundColor: Styles.purpleNurple,
title: Text(
ref.watch(appBarTitleProvider),
2023-07-15 17:23:27 -06:00
),
),
2023-07-19 02:16:13 -06:00
body: ref.watch(currentHomePageProvider),
2023-07-15 17:23:27 -06:00
);
}
2023-07-22 21:29:32 -06:00
toggleDrawer() async {
final key = ref.read(scaffoldKeyProvider);
if (key.currentState != null && key.currentState!.isDrawerOpen) {
key.currentState!.openEndDrawer();
} else if (key.currentState != null) {
key.currentState!.openDrawer();
}
}
2023-07-15 17:23:27 -06:00
}
2023-07-19 02:16:13 -06:00
2023-07-22 21:29:32 -06:00
final scaffoldKeyProvider = Provider<GlobalKey<ScaffoldState>>(
(ref) => GlobalKey<ScaffoldState>(),
);
2023-07-19 02:16:13 -06:00
final currentHomePageProvider = StateProvider<Widget>(
2023-07-22 21:29:32 -06:00
(ref) => const BudgetOverviewScreen(initialData: {}),
2023-07-19 02:16:13 -06:00
);
final appBarTitleProvider = Provider<String>(
(ref) {
final currentPageName = ref.watch(currentHomePageProvider).toString();
switch (currentPageName) {
case 'BudgetOverviewScreen':
return 'Budget';
2023-07-22 21:29:32 -06:00
case 'SharedNotesScreen':
return 'Notes';
2023-07-19 02:16:13 -06:00
default:
return '';
}
},
);