2023-12-17 23:00:31 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2024-01-09 12:34:44 +01:00
|
|
|
import 'package:moody/utils/slide_direction.dart';
|
|
|
|
import 'package:moody/utils/widgets/question_slider_widget.dart';
|
2024-01-13 17:07:11 +01:00
|
|
|
import 'package:moody/views/about_page/about_page.dart';
|
2024-01-01 18:31:10 +01:00
|
|
|
import 'package:moody/views/color_page/color_page.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';
|
2024-01-13 17:07:11 +01:00
|
|
|
import 'package:moody/views/imprint_page/imprint_page.dart';
|
2023-12-18 17:51:22 +01:00
|
|
|
import 'package:moody/views/settings_page/settings_page.dart';
|
2024-01-01 18:31:10 +01:00
|
|
|
import 'package:moody/views/start_page/start_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: '/',
|
2024-01-09 12:34:44 +01:00
|
|
|
pageBuilder: (context, state) => _noAnimationTransition(context, state, const StartPage()),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: '/moods',
|
2024-01-09 12:34:44 +01:00
|
|
|
builder: (context, state) => const StatisticPage(),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
|
|
|
GoRoute(
|
2023-12-18 17:51:22 +01:00
|
|
|
path: '/settings',
|
2024-01-09 12:34:44 +01:00
|
|
|
pageBuilder: (context, state) => _noAnimationTransition(context, state, const SettingsPage()),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
2023-12-18 17:51:22 +01:00
|
|
|
GoRoute(
|
|
|
|
path: '/statistic',
|
2024-01-09 12:34:44 +01:00
|
|
|
// ignore: prefer_const_constructors
|
|
|
|
pageBuilder: (context, state) => _noAnimationTransition(context, state, StatisticPage()),
|
2023-12-18 17:51:22 +01:00
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: '/home',
|
2024-01-09 12:34:44 +01:00
|
|
|
pageBuilder: (context, state) => _noAnimationTransition(context, state, const HomePage()),
|
2024-01-01 18:31:10 +01:00
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: '/first',
|
2024-01-09 12:34:44 +01:00
|
|
|
pageBuilder: (context, state) => _noAnimationTransition(context, state, const FirstPage()),
|
2024-01-01 18:31:10 +01:00
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: '/color',
|
2024-01-09 12:34:44 +01:00
|
|
|
pageBuilder: (context, state) => _noAnimationTransition(context, state, const ColorPage()),
|
2024-01-01 18:31:10 +01:00
|
|
|
),
|
2024-01-13 17:07:11 +01:00
|
|
|
GoRoute(
|
|
|
|
path: '/imprint',
|
|
|
|
pageBuilder: (context, state) => _noAnimationTransition(context, state, const ImprintPage()),
|
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: '/about',
|
|
|
|
pageBuilder: (context, state) => _noAnimationTransition(context, state, const AboutPage()),
|
|
|
|
),
|
2023-12-17 23:00:31 +01:00
|
|
|
GoRoute(
|
|
|
|
path: '/write',
|
|
|
|
builder: (context, state) {
|
2024-01-01 19:52:42 +01:00
|
|
|
final sliderdata = state.extra as SliderChangeData;
|
|
|
|
return WritePage(sliderData: sliderdata);
|
2023-12-17 23:00:31 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
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
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
/* A Slide Transition that will may be used in future versions
|
|
|
|
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);
|
2023-12-18 17:51:22 +01:00
|
|
|
|
|
|
|
return CustomTransitionPage(
|
|
|
|
key: state.pageKey,
|
|
|
|
child: child,
|
|
|
|
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
|
|
var end = Offset.zero;
|
|
|
|
var curve = Curves.easeInOut;
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
var tween = Tween(begin: beginOffset, end: end).chain(CurveTween(curve: curve));
|
2023-12-18 17:51:22 +01:00
|
|
|
var offsetAnimation = animation.drive(tween);
|
|
|
|
|
|
|
|
return SlideTransition(
|
|
|
|
position: offsetAnimation,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2024-01-09 12:34:44 +01:00
|
|
|
}*/
|
2023-12-18 17:51:22 +01:00
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
SlideDirection determineSlideDirection(String currentRoute, String targetRoute) {
|
2023-12-18 17:51:22 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2024-01-09 12:34:44 +01:00
|
|
|
return currentRoute.compareTo(targetRoute) < 0 ? SlideDirection.left : SlideDirection.right;
|
2023-12-18 17:51:22 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
CustomTransitionPage<dynamic> _noAnimationTransition(BuildContext context, GoRouterState state, Widget child) {
|
2023-12-18 17:51:22 +01:00
|
|
|
return CustomTransitionPage(
|
|
|
|
key: state.pageKey,
|
|
|
|
child: child,
|
|
|
|
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
|
|
// Simply return the child with no animation
|
|
|
|
return child;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|