feat(proj): init
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:please_pay_me/app/home_tabs.dart';
|
||||
import 'package:please_pay_me/features/auth/login_screen.dart';
|
||||
import 'package:please_pay_me/features/auth/session_controller.dart';
|
||||
import 'package:please_pay_me/features/splash/splash_screen.dart';
|
||||
import 'package:please_pay_me/features/budgets/budgets_controller.dart';
|
||||
import 'package:please_pay_me/features/journal/journal_controller.dart';
|
||||
import 'package:please_pay_me/features/work/jobs_controller.dart';
|
||||
import 'package:please_pay_me/core/branding/app_brand.dart';
|
||||
import 'package:please_pay_me/theme/theme.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class PleasePayMeApp extends StatelessWidget {
|
||||
PleasePayMeApp({super.key, required this.session, ThemeController? theme})
|
||||
: theme = theme ?? ThemeController(store: MemoryThemeStore());
|
||||
|
||||
final SessionController session;
|
||||
final ThemeController theme;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<SessionController>.value(value: session),
|
||||
ChangeNotifierProvider<ThemeController>.value(value: theme),
|
||||
],
|
||||
child: Consumer<ThemeController>(
|
||||
builder: (context, theme, _) {
|
||||
final platform = MediaQuery.platformBrightnessOf(context);
|
||||
final brightness = theme.resolve(platform);
|
||||
|
||||
return CupertinoApp(
|
||||
title: AppBrand.name,
|
||||
theme: brightness == Brightness.dark ? buildDarkTheme() : buildLightTheme(),
|
||||
locale: const Locale('ru'),
|
||||
supportedLocales: const [Locale('ru'), Locale('en')],
|
||||
localizationsDelegates: const [
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
builder: (context, child) {
|
||||
final overlay = systemUiOverlayFor(brightness);
|
||||
SystemChrome.setSystemUIOverlayStyle(overlay);
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: overlay,
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(platformBrightness: brightness),
|
||||
child: child!,
|
||||
),
|
||||
);
|
||||
},
|
||||
home: const _SessionGate(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SessionGate extends StatelessWidget {
|
||||
const _SessionGate();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final session = context.watch<SessionController>();
|
||||
|
||||
return switch (session.status) {
|
||||
SessionStatus.restoring => const SplashScreen(),
|
||||
SessionStatus.signedOut => const LoginScreen(),
|
||||
SessionStatus.signedIn => AppDataScope(
|
||||
key: ValueKey(session.sessionKey),
|
||||
session: session,
|
||||
child: const HomeTabs(),
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Feature controllers bound to the current session. Rebuilt from scratch when
|
||||
/// the session changes, so no stale data survives a re-login.
|
||||
class AppDataScope extends StatelessWidget {
|
||||
const AppDataScope({
|
||||
super.key,
|
||||
required this.session,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final SessionController session;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => BudgetsController(
|
||||
budgets: session.budgets,
|
||||
expenses: session.expenses,
|
||||
)..load(),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => JournalController(expenses: session.expenses)..load(),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => JobsController(jobs: session.jobs)..load(),
|
||||
),
|
||||
],
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:please_pay_me/features/budgets/budgets_screen.dart';
|
||||
import 'package:please_pay_me/features/journal/journal_screen.dart';
|
||||
import 'package:please_pay_me/features/overview/overview_screen.dart';
|
||||
import 'package:please_pay_me/features/profile/profile_screen.dart';
|
||||
import 'package:please_pay_me/features/work/work_screen.dart';
|
||||
import 'package:please_pay_me/ui/ui.dart';
|
||||
|
||||
/// Root tab bar. Each tab keeps its own navigator so modal sheets and alerts
|
||||
/// stay inside the tab, as iOS expects.
|
||||
class HomeTabs extends StatelessWidget {
|
||||
const HomeTabs({super.key});
|
||||
|
||||
static const _tabs = [
|
||||
AppTabItem(
|
||||
icon: CupertinoIcons.chart_pie,
|
||||
activeIcon: CupertinoIcons.chart_pie_fill,
|
||||
label: 'Обзор',
|
||||
),
|
||||
AppTabItem(
|
||||
icon: CupertinoIcons.list_bullet,
|
||||
label: 'Журнал',
|
||||
),
|
||||
AppTabItem(
|
||||
icon: CupertinoIcons.money_rubl_circle,
|
||||
activeIcon: CupertinoIcons.money_rubl_circle_fill,
|
||||
label: 'Бюджеты',
|
||||
),
|
||||
AppTabItem(
|
||||
icon: CupertinoIcons.briefcase,
|
||||
activeIcon: CupertinoIcons.briefcase_fill,
|
||||
label: 'Работа',
|
||||
),
|
||||
AppTabItem(
|
||||
icon: CupertinoIcons.person,
|
||||
activeIcon: CupertinoIcons.person_fill,
|
||||
label: 'Профиль',
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoTabScaffold(
|
||||
tabBar: AppTabBar(items: _tabs, currentIndex: 0, onTap: (_) {}),
|
||||
tabBuilder: (context, index) => CupertinoTabView(
|
||||
builder: (context) => switch (index) {
|
||||
0 => const OverviewScreen(),
|
||||
1 => const JournalScreen(),
|
||||
2 => const BudgetsScreen(),
|
||||
3 => const WorkScreen(),
|
||||
_ => const ProfileScreen(),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user