ModernMemoires/lib/main.dart

129 lines
3.6 KiB
Dart
Raw Normal View History

2023-12-17 23:00:31 +01:00
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
2023-12-18 17:51:22 +01:00
import 'package:moody/utils/SlideDirection.dart';
2023-12-17 23:00:31 +01:00
import 'package:moody/views/entry_view/entry_page.dart';
2023-12-18 17:51:22 +01:00
import 'package:moody/views/first_page/first_page.dart';
import 'package:moody/views/home_page/home_page.dart';
2023-12-17 23:00:31 +01:00
import 'package:moody/views/home_page/kalendartryhome_page.dart';
2023-12-18 17:51:22 +01:00
import 'package:moody/views/settings_page/settings_page.dart';
2023-12-17 23:00:31 +01:00
import 'package:moody/views/statistic/statistic_page.dart';
import 'package:moody/views/write_page/write_page.dart';
void main() => runApp(const MyApp());
final GoRouter _router = GoRouter(
routes: [
GoRoute(
path: '/',
2023-12-18 17:51:22 +01:00
pageBuilder: (context, state) =>
_noAnimationTransition(context, state, FirstPage()),
2023-12-17 23:00:31 +01:00
),
GoRoute(
path: '/moods',
builder: (context, state) => CalendarPage(),
),
GoRoute(
2023-12-18 17:51:22 +01:00
path: '/settings',
pageBuilder: (context, state) =>
_noAnimationTransition(context, state, SettingsPage()),
2023-12-17 23:00:31 +01:00
),
2023-12-18 17:51:22 +01:00
GoRoute(
path: '/statistic',
pageBuilder: (context, state) =>
_noAnimationTransition(context, state, StatisticPage()),
),
GoRoute(
path: '/home',
pageBuilder: (context, state) =>
_noAnimationTransition(context, state, HomePage()),
),
2023-12-17 23:00:31 +01:00
GoRoute(
path: '/write',
builder: (context, state) {
final moodPercentage = state.extra as double;
return WritePage(moodPercentage: moodPercentage);
},
),
GoRoute(
path: '/entry',
builder: (context, state) {
final date = state.extra as DateTime;
return EntryPage(
date: date,
);
},
),
],
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
theme: ThemeData(fontFamily: 'ABCFavorit'),
routerConfig: _router,
);
}
}
2023-12-18 17:51:22 +01:00
CustomTransitionPage<dynamic> _createSlideTransition(BuildContext context,
GoRouterState state, Widget child, SlideDirection direction) {
var beginOffset =
direction == SlideDirection.left ? Offset(1.0, 0.0) : Offset(-1.0, 0.0);
return CustomTransitionPage(
key: state.pageKey,
child: child,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var end = Offset.zero;
var curve = Curves.easeInOut;
var tween =
Tween(begin: beginOffset, end: end).chain(CurveTween(curve: curve));
var offsetAnimation = animation.drive(tween);
return SlideTransition(
position: offsetAnimation,
child: child,
);
},
);
}
SlideDirection determineSlideDirection(
String currentRoute, String targetRoute) {
print(currentRoute);
print(targetRoute);
if (currentRoute == targetRoute) {
print("Sameroute pls fix!!");
}
if (targetRoute == "/statistic") {
return SlideDirection.right;
} else if (targetRoute == "/settings") {
return SlideDirection.left;
} else if (targetRoute == "/") {
if (currentRoute == "/statistic") {
return SlideDirection.left;
} else if (currentRoute == "/settings") {
return SlideDirection.right;
}
}
return currentRoute.compareTo(targetRoute) < 0
? SlideDirection.left
: SlideDirection.right;
}
CustomTransitionPage<dynamic> _noAnimationTransition(
BuildContext context, GoRouterState state, Widget child) {
return CustomTransitionPage(
key: state.pageKey,
child: child,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
// Simply return the child with no animation
return child;
},
);
}