2022-10-15 16:35:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-11-26 19:42:21 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2022-10-29 18:02:45 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2022-10-30 18:30:12 +00:00
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2022-11-27 20:22:56 +00:00
|
|
|
import 'package:lightmeter/data/permissions_service.dart';
|
2022-11-26 19:29:00 +00:00
|
|
|
import 'package:lightmeter/screens/settings/settings_page_route_builder.dart';
|
2022-11-27 20:31:49 +00:00
|
|
|
import 'package:lightmeter/screens/settings/settings_screen.dart';
|
2022-11-27 20:22:56 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2022-10-24 20:25:38 +00:00
|
|
|
|
2022-10-30 18:30:12 +00:00
|
|
|
import 'generated/l10n.dart';
|
2022-10-29 18:02:45 +00:00
|
|
|
import 'models/photography_value.dart';
|
2022-11-26 19:29:00 +00:00
|
|
|
import 'res/dimens.dart';
|
2022-10-24 20:25:38 +00:00
|
|
|
import 'res/theme.dart';
|
2022-10-29 18:02:45 +00:00
|
|
|
import 'screens/metering/metering_bloc.dart';
|
2022-11-27 20:31:49 +00:00
|
|
|
import 'screens/metering/metering_screen.dart';
|
2022-10-30 18:06:51 +00:00
|
|
|
import 'utils/stop_type_provider.dart';
|
2022-10-15 16:35:35 +00:00
|
|
|
|
|
|
|
void main() {
|
2022-11-26 19:29:00 +00:00
|
|
|
runApp(const Application());
|
2022-10-15 16:35:35 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 19:29:00 +00:00
|
|
|
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
|
|
|
|
|
|
|
|
class Application extends StatefulWidget {
|
|
|
|
const Application({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<Application> createState() => _ApplicationState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ApplicationState extends State<Application> with TickerProviderStateMixin {
|
|
|
|
late final AnimationController _animationController;
|
|
|
|
late final _settingsRouteObserver = _SettingsRouteObserver(onPush: _onSettingsPush, onPop: _onSettingsPop);
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-11-26 19:42:21 +00:00
|
|
|
final mySystemTheme = SystemUiOverlayStyle.light.copyWith(
|
2022-12-04 19:46:11 +00:00
|
|
|
statusBarColor: Colors.transparent,
|
2022-11-26 19:42:21 +00:00
|
|
|
statusBarBrightness: Brightness.light,
|
|
|
|
statusBarIconBrightness: Brightness.dark,
|
2022-12-04 19:46:11 +00:00
|
|
|
systemNavigationBarColor: Colors.transparent,
|
|
|
|
systemNavigationBarIconBrightness: Brightness.dark,
|
2022-11-26 19:42:21 +00:00
|
|
|
);
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(mySystemTheme);
|
2022-11-26 19:29:00 +00:00
|
|
|
// 0 - collapsed
|
|
|
|
// 1 - expanded
|
|
|
|
_animationController = AnimationController(
|
|
|
|
value: 0,
|
|
|
|
duration: Dimens.durationM,
|
|
|
|
reverseDuration: Dimens.durationSM,
|
|
|
|
vsync: this,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_animationController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
2022-10-15 16:35:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-27 20:22:56 +00:00
|
|
|
return Provider(
|
|
|
|
create: (context) => PermissionsService(),
|
|
|
|
child: StopTypeProvider(
|
|
|
|
child: BlocProvider(
|
|
|
|
create: (context) => MeteringBloc(context.read<StopType>()),
|
|
|
|
child: MaterialApp(
|
|
|
|
theme: ThemeData(
|
|
|
|
useMaterial3: true,
|
|
|
|
colorScheme: lightColorScheme,
|
|
|
|
),
|
|
|
|
navigatorObservers: [_settingsRouteObserver],
|
|
|
|
localizationsDelegates: const [
|
|
|
|
S.delegate,
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
],
|
|
|
|
supportedLocales: S.delegate.supportedLocales,
|
2022-11-29 18:46:23 +00:00
|
|
|
home: MeteringScreen(animationController: _animationController),
|
2022-11-27 20:31:49 +00:00
|
|
|
routes: {
|
|
|
|
"metering": (context) => MeteringScreen(animationController: _animationController),
|
|
|
|
"settings": (context) => const SettingsScreen(),
|
|
|
|
},
|
2022-10-30 18:06:51 +00:00
|
|
|
),
|
2022-10-29 18:02:45 +00:00
|
|
|
),
|
2022-10-15 16:38:34 +00:00
|
|
|
),
|
2022-10-15 16:35:35 +00:00
|
|
|
);
|
|
|
|
}
|
2022-11-26 19:29:00 +00:00
|
|
|
|
|
|
|
void _onSettingsPush() {
|
|
|
|
if (!_animationController.isAnimating && _animationController.status != AnimationStatus.completed) {
|
|
|
|
_animationController.forward();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onSettingsPop() {
|
2022-11-26 19:34:28 +00:00
|
|
|
Future.delayed(Dimens.durationM).then((_) {
|
2022-11-26 19:29:00 +00:00
|
|
|
if (!_animationController.isAnimating && _animationController.status != AnimationStatus.dismissed) {
|
|
|
|
_animationController.reverse();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsRouteObserver extends RouteObserver<SettingsPageRouteBuilder> {
|
|
|
|
final VoidCallback onPush;
|
|
|
|
final VoidCallback onPop;
|
|
|
|
|
|
|
|
_SettingsRouteObserver({
|
|
|
|
required this.onPush,
|
|
|
|
required this.onPop,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
|
|
super.didPush(route, previousRoute);
|
|
|
|
if (route is SettingsPageRouteBuilder) {
|
|
|
|
onPush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
|
|
super.didPop(route, previousRoute);
|
|
|
|
if (previousRoute is PageRoute && route is SettingsPageRouteBuilder) {
|
|
|
|
onPop();
|
|
|
|
}
|
|
|
|
}
|
2022-10-15 16:35:35 +00:00
|
|
|
}
|