initial commit
This commit is contained in:
11
lib/core/route/base_route.dart
Normal file
11
lib/core/route/base_route.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class BaseRoute {
|
||||
String routeName;
|
||||
Widget clazz;
|
||||
|
||||
BaseRoute({
|
||||
required this.routeName,
|
||||
required this.clazz,
|
||||
});
|
||||
}
|
||||
62
lib/core/route/route.dart
Normal file
62
lib/core/route/route.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:cims_apps/features/splash_screen.dart';
|
||||
import 'package:cims_apps/routes/all_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum RouteType { push, pushReplace, pushRemove }
|
||||
|
||||
const initialRoute = SplashScreen.routeName;
|
||||
|
||||
Route<dynamic>? generateRoutes(RouteSettings settings) {
|
||||
AllRoute().key();
|
||||
return MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
AllRoute.allRouteMap[settings.name]?.clazz ?? const SizedBox(),
|
||||
settings: settings);
|
||||
}
|
||||
|
||||
Future routePush(
|
||||
BuildContext context, {
|
||||
RouteType? routeType,
|
||||
Object? arguments,
|
||||
required Widget page,
|
||||
}) {
|
||||
var pageRoute = MaterialPageRoute(
|
||||
builder: (context) => page,
|
||||
settings: RouteSettings(name: "/${page.toString()}", arguments: arguments),
|
||||
);
|
||||
if (routeType == RouteType.pushReplace) {
|
||||
return Navigator.pushReplacement(
|
||||
context,
|
||||
pageRoute,
|
||||
result: ModalRoute.of(context)?.currentResult,
|
||||
);
|
||||
}
|
||||
if (routeType == RouteType.pushRemove) {
|
||||
return Navigator.of(context).pushAndRemoveUntil(
|
||||
pageRoute,
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
|
||||
return Navigator.push(context, pageRoute);
|
||||
}
|
||||
|
||||
Future routeNamed(
|
||||
BuildContext context, {
|
||||
RouteType? routeType,
|
||||
Object? arguments,
|
||||
required String routeName,
|
||||
}) {
|
||||
if (routeType == RouteType.pushReplace) {
|
||||
return Navigator.pushReplacementNamed(context, routeName,
|
||||
arguments: arguments, result: ModalRoute.of(context)?.currentResult);
|
||||
}
|
||||
if (routeType == RouteType.pushRemove) {
|
||||
return Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
routeName,
|
||||
(route) => false,
|
||||
arguments: arguments,
|
||||
);
|
||||
}
|
||||
return Navigator.pushNamed(context, routeName);
|
||||
}
|
||||
37
lib/core/route/route_observer.dart
Normal file
37
lib/core/route/route_observer.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CoreRouteObserver extends NavigatorObserver {
|
||||
@override
|
||||
void didPush(Route route, Route? previousRoute) {
|
||||
if (kDebugMode) {
|
||||
log("\nRoute Name: ${route.settings.name} - push\n");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didPop(Route route, Route? previousRoute) {
|
||||
super.didPop(route, previousRoute);
|
||||
if (kDebugMode) {
|
||||
log("\nRoute Name: ${route.settings.name} - pop\n");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didRemove(Route route, Route? previousRoute) {
|
||||
if (kDebugMode) {
|
||||
log("\nRoute Name: ${route.settings.name} - remove\n");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didReplace({Route? newRoute, Route? oldRoute}) {
|
||||
if (kDebugMode) {
|
||||
if (newRoute != null) {
|
||||
log("\nRoute Name: ${newRoute.settings.name} - replace\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
lib/core/utils/size_config.dart
Normal file
15
lib/core/utils/size_config.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SizeConfig {
|
||||
//initOnStartUp
|
||||
static MediaQueryData mediaQuery = const MediaQueryData();
|
||||
static bool isMobile = true;
|
||||
static double width = 0;
|
||||
static double height = 0;
|
||||
|
||||
static void initOnStartUp(BuildContext context) {
|
||||
mediaQuery = MediaQuery.of(context);
|
||||
width = mediaQuery.size.width;
|
||||
height = mediaQuery.size.height;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user