151 lines
4.3 KiB
Dart
151 lines
4.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:helpers/helpers/misc_build/build_media.dart';
|
|
import 'package:rluv/features/budget/screens/budget_overview.dart';
|
|
import 'package:rluv/features/notes/screens/notes_screen.dart';
|
|
import 'package:rluv/features/settings/screens/settings_screen.dart';
|
|
import 'package:rluv/global/styles.dart';
|
|
import 'package:rluv/global/utils.dart';
|
|
import 'package:rluv/global/widgets/drawer_button.dart';
|
|
|
|
import 'global/store.dart';
|
|
|
|
void main() async {
|
|
final _ = Store().prefs;
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ProviderScope(
|
|
child: MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
title: 'Flutter Demo',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
),
|
|
home: const Home(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class Home extends ConsumerStatefulWidget {
|
|
const Home({super.key});
|
|
|
|
@override
|
|
ConsumerState<Home> createState() => _HomeState();
|
|
}
|
|
|
|
class _HomeState extends ConsumerState<Home> {
|
|
Map<String, dynamic> initData = {};
|
|
final drawerColors = Styles.curatedColors;
|
|
@override
|
|
void initState() {
|
|
setDevicePortraitOrientation();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (ref.watch(currentHomePageProvider).toString() ==
|
|
"BudgetOverviewScreen") {
|
|
initData = {};
|
|
}
|
|
return Scaffold(
|
|
key: ref.read(scaffoldKeyProvider),
|
|
resizeToAvoidBottomInset: false,
|
|
drawer: Drawer(
|
|
backgroundColor: Styles.purpleNurple,
|
|
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),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
appBar: AppBar(
|
|
backgroundColor: Styles.purpleNurple,
|
|
title: Text(
|
|
ref.watch(appBarTitleProvider),
|
|
),
|
|
),
|
|
body: ref.watch(currentHomePageProvider),
|
|
);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
final scaffoldKeyProvider = Provider<GlobalKey<ScaffoldState>>(
|
|
(ref) => GlobalKey<ScaffoldState>(),
|
|
);
|
|
|
|
final currentHomePageProvider = StateProvider<Widget>(
|
|
(ref) => const BudgetOverviewScreen(initialData: {}),
|
|
);
|
|
|
|
final appBarTitleProvider = Provider<String>(
|
|
(ref) {
|
|
final currentPageName = ref.watch(currentHomePageProvider).toString();
|
|
switch (currentPageName) {
|
|
case 'BudgetOverviewScreen':
|
|
return 'Budget';
|
|
case 'SharedNotesScreen':
|
|
return 'Notes';
|
|
default:
|
|
return '';
|
|
}
|
|
},
|
|
);
|