- Created generated_plugin_registrant.cc and generated_plugin_registrant.h to manage plugin registration. - Added generated_plugins.cmake for plugin configuration in CMake. - Implemented CMakeLists.txt for the Windows runner, defining build settings and dependencies. - Created Runner.rc for application resources including versioning and icons. - Developed flutter_window.cpp and flutter_window.h to manage the Flutter window lifecycle. - Implemented main.cpp as the entry point for the Windows application. - Added resource.h for resource definitions. - Included app icon in resources. - Created runner.exe.manifest for application settings. - Developed utils.cpp and utils.h for console management and command line argument handling. - Implemented win32_window.cpp and win32_window.h for high DPI-aware window management.
69 lines
2.2 KiB
Dart
69 lines
2.2 KiB
Dart
import 'package:marco/helpers/widgets/my_middleware.dart';
|
|
import 'package:marco/helpers/widgets/my_route.dart';
|
|
import 'package:marco/helpers/widgets/my_route_exception.dart';
|
|
import 'package:marco/helpers/widgets/my_routes.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
class MyRouter {
|
|
static T? getArgs<T>(BuildContext context) {
|
|
try {
|
|
Object? args = ModalRoute.of(context)?.settings.arguments;
|
|
if (args is T) return args;
|
|
return null;
|
|
} catch (e) {
|
|
throw RouteException(
|
|
"Use getArgs in onReady state. Don't use in constructor or initState");
|
|
}
|
|
}
|
|
|
|
static MyRoute? _getRouteFromRouteName(String routeName) {
|
|
for (MyRoute route in MyRoutes.routes) {
|
|
if (route.name.compareTo(routeName) == 0) return route;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static MyRoute? getSecuredRouteFromRouteName(String routeName) {
|
|
Uri uri = Uri.parse(routeName);
|
|
var route0 = uri.path;
|
|
MyRoute? route = _getRouteFromRouteName(route0);
|
|
if (route == null) return null;
|
|
|
|
if (route.middlewares != null && route.middlewares!.isNotEmpty) {
|
|
for (MyMiddleware middleware in route.middlewares!) {
|
|
String redirectedRouteName = middleware.handle(route0);
|
|
if (redirectedRouteName.compareTo(route0) != 0) {
|
|
return getSecuredRouteFromRouteName(redirectedRouteName);
|
|
}
|
|
}
|
|
}
|
|
return route;
|
|
}
|
|
|
|
static Future<T?> pushNamed<T extends Object?>(
|
|
BuildContext context,
|
|
String routeName, {
|
|
Object? arguments,
|
|
}) async {
|
|
MyRoute? route = getSecuredRouteFromRouteName(routeName);
|
|
if (route == null) {
|
|
throw RouteException("'$routeName' Route is not implemented");
|
|
}
|
|
return Navigator.of(context).pushNamed<T>(route.name, arguments: arguments);
|
|
}
|
|
|
|
static Future<T?> pushReplacementNamed<T extends Object?, TO extends Object?>(
|
|
BuildContext context,
|
|
String routeName, {
|
|
Object? arguments,
|
|
}) async {
|
|
MyRoute? route = getSecuredRouteFromRouteName(routeName);
|
|
if (route == null) {
|
|
throw RouteException("'$routeName' Route is not implemented");
|
|
}
|
|
return Navigator.of(context)
|
|
.pushReplacementNamed<T, TO>(route.name, arguments: arguments);
|
|
}
|
|
}
|