1 year ago
#373993
adominas20
Is there a way to dynamically state which flavor route files to import to deal with boilerplate code when making new flavors?
One of our apps has quite a few Flutter flavors, where a router needs to be set up for each flavor in order to navigate around the app, as the individual router file will contain the correct imports to the views.
For example, we might have MenuView that exists in
views/flavor1/menu_view.dart
and
views/flavor2/menu_view.dart
and flavor_2_router.dart
would navigate to the MenuView
as defined by the import ../flavor2/_views.dart
statement.
The problem is, when adding a new flavor, or a new view, it’s getting slightly cumbersome to copy and paste routes which are shared across all flavors. I’m essentially wondering if there’s a way to dynamically state which files to import (and thus get the classes from) or another type of design pattern that would help deal with this growing boilerplate code?
Fragment of the router code:
// Flavor Specific Imports
import 'package:mycompany/ui/flavors/flavor_1/views/_views.dart';
Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case AppUpgradeRoute:
return _getPageRoute(
routeName: settings.name,
viewToShow: AppUpgradeView(),
);
case LoginRoute:
return _getPageRoute(
routeName: settings.name,
viewToShow: LoginView(),
);
case StartUpRoute:
var startupSettings = settings.arguments as StartupSettings;
return _getPageRoute(
routeName: settings.name,
viewToShow: StartUpView(startupSettings: startupSettings),
);
...
Any suggestions?
flutter
dart
android-build-flavors
android-flavors
0 Answers
Your Answer