I have a list of routes with more than 50 lines and I wish to simplify it because it is very long and messy. Below is the example of current routes. Is there anyway I can extract it into separate files? For example, put //2 in routes2.dart file and //3 in routes3.dart file? How do I call them back in MyApp?
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider( create: (_) => SettingsNotifier()),
ChangeNotifierProvider(create: (_) => InterstitialTimerNotifier()),
ChangeNotifierProvider(create: (_) => InterstitialReadyNotifier()),
ChangeNotifierProvider(create: (_) => PolicyNotifier()),
],
child: MaterialApp(
themeMode:ThemeMode.system,
theme: ThemeClass.lightTheme,
darkTheme: ThemeClass.darkTheme,
initialRoute: HomeScreen.id,
routes: {
//1. Home
HomeScreen.id: (context) => HomeScreen(),
//2. Puasa
PuasaScreen.id: (context) => PuasaScreen(),
DoaBerbuka.id: (context) => DoaBerbuka(),
NiatPuasa.id: (context) => NiatPuasa(),
WaktuMustajabDoa.id: (context) => WaktuMustajabDoa(),
PuasaPengenalanScreen.id: (context) => PuasaPengenalanScreen(),
PuasaReference.id: (context) => PuasaReference(),
//3. Solat Tarawih
TarawihScreen.id: (context) => TarawihScreen(),
TarawihPengenalanScreen.id: (context) => TarawihPengenalanScreen(),
TarawihNiat.id:(context) => TarawihNiat(),
TarawihTakrif.id: (context) => TarawihTakrif(),
TarawihDalilScreen.id: (context) => TarawihDalilScreen(),
TarawihHukum.id: (context) => TarawihHukum(),
TarawihReference.id: (context) => TarawihReference(),
TarawihWaktuSolat.id: (context) => TarawihWaktuSolat(),
TarawihKelebihanScreen.id: (context) => TarawihKelebihanScreen(),
TarawihBilanganRakaat.id: (context) => TarawihBilanganRakaat(),
Tarawih8Screen.id: (context) => Tarawih8Screen(),
Tarawih8TatacaraScreen.id: (context) => Tarawih8TatacaraScreen(),
//4. Solat Witir
Tarawih8WitirScreen.id: (context) => Tarawih8WitirScreen(),
Tarawih8WitirRakaat1.id: (context) => Tarawih8WitirRakaat1(),
Tarawih8WitirRakaat2.id: (context) => Tarawih8WitirRakaat2(),
Tarawih8WitirRakaat3.id: (context) => Tarawih8WitirRakaat3(),
TarawihTahlil.id: (context) => TarawihTahlil(),
//There're more routes after this
}),
);
}
}
routes: takes Map<String, WidgetBuilder>, you can create
a dart file and create a map like,
final Map<String, WidgetBuilder> route2 = {
PuasaScreen.id: (context) => PuasaScreen(),
.....
};
same goes for routes3.dart.
and you can add theses routes on MaterialApp like
return MaterialApp(
routes: {
HomeScreen.id: (context) => HomeScreen(),
...route2, /// variable name
...route3,
},
);
This is the updated code after applying suggestions from #OMiShah.
I created new dart files for the routes. For example, route_puasa.dart:
import ...
Map routes_puasa = {
PuasaScreen.id: (context) => PuasaScreen(),
DoaBerbuka.id: (context) => DoaBerbuka(),
NiatPuasa.id: (context) => NiatPuasa(),
WaktuMustajabDoa.id: (context) => WaktuMustajabDoa(),
PuasaPengenalanScreen.id: (context) => PuasaPengenalanScreen(),
PuasaReference.id: (context) => PuasaReference(),
};
Then call it in MyApp using ... Spread Operator
routes: {
...routes_puasa,
...route_tarawih,
...routes_tarawih20,
...routes_zakat,
}
Works perfectly!
I have this graduation project . I converted my figma to flutter(dart). I have running an andriod simulation on intelli jetbrains. however i keep getting this error :
"Could not find a generator for route RouteSettings("/", null) in the _WidgetsAppStat
If u can help me out it would be greatly appreciated.
This is the code if u could help it would be really great. I am trying to see if my figma design is being implemented properly. I have been running a hundred of times.
The full main.dart code is posted below:
void main() {
runApp(Covid_19_20AppApp());
}
class Covid_19_20AppApp extends StatelessWidget {
get generateRoute => null;
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Covid-19',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/GeneratedAndroid1Widget',
onGenerateRoute:generateRoute,
routes: {
'/GeneratedAndroid5Widget': (context) => GeneratedAndroid5Widget(),
'/GeneratedAndroid13Widget': (context) => GeneratedAndroid13Widget(),
'/GeneratedAndroid16Widget': (context) => GeneratedAndroid16Widget(),
'/GeneratedAndroid20Widget': (context) => GeneratedAndroid20Widget(),
'/GeneratedAndroid23Widget': (context) => GeneratedAndroid23Widget(),
'/GeneratedAndroid25Widget': (context) => GeneratedAndroid25Widget(),
'/GeneratedAndroid29Widget': (context) => GeneratedAndroid29Widget(),
'/GeneratedLowWidget12': (context) => GeneratedLowWidget12(),
'/GeneratedModerateWidget12': (context) => GeneratedModerateWidget12(),
'/GeneratedAndroid6Widget': (context) => GeneratedAndroid6Widget(),
'/GeneratedHoverStateWidget': (context) => GeneratedHoverStateWidget(),
'/GeneratedPlaceholderTextWidget7': (context) => GeneratedPlaceholderTextWidget7(),
'/GeneratedListBoxtitleWidget7': (context) => GeneratedListBoxtitleWidget7(),
'/GeneratedTextWidget': (context) => GeneratedTextWidget(),
'/GeneratedListboxComponentWidget7': (context) =>
GeneratedListboxComponentWidget7(),
'/GeneratedListboxComponentWidget8': (context) =>
GeneratedListboxComponentWidget8(),
'/GeneratedListboxComponentWidget9': (context) =>
GeneratedListboxComponentWidget9(),
'/GeneratedListboxComponentWidget10': (context) =>
GeneratedListboxComponentWidget10(),
'/GeneratedComponent1Widget1': (context) => GeneratedComponent1Widget1(),
'/GeneratedComponent3Widget1': (context) => GeneratedComponent3Widget1(),
'/GeneratedComponent8Widget': (context) => GeneratedComponent8Widget(),
'/GeneratedTextWidget1': (context) => GeneratedTextWidget1(),
'/GeneratedComponent2Widget': (context) => GeneratedComponent2Widget(),
'/GeneratedVectorWidget218': (context) => GeneratedVectorWidget218(),
'/GeneratedVectorWidget219': (context) => GeneratedVectorWidget219(),
'/GeneratedTextboxuncheckedWidget6': (context) =>
GeneratedTextboxuncheckedWidget6(),
'/GeneratedTextboxuncheckedWidget7': (context) =>
GeneratedTextboxuncheckedWidget7(),
'/GeneratedTextboxuncheckedWidget8': (context) =>
GeneratedTextboxuncheckedWidget8(),
'/GeneratedTextboxuncheckedWidget9': (context) =>
GeneratedTextboxuncheckedWidget9(),
'/GeneratedTextboxuncheckedWidget10': (context) =>
GeneratedTextboxuncheckedWidget10(),
'/GeneratedTextboxuncheckedWidget11': (context) =>
GeneratedTextboxuncheckedWidget11(),
'/GeneratedTextboxuncheckedWidget12': (context) =>
GeneratedTextboxuncheckedWidget12(),
'/GeneratedTextboxuncheckedWidget13': (context) =>
GeneratedTextboxuncheckedWidget13(),
'/GeneratedTextboxuncheckedWidget14': (context) =>
GeneratedTextboxuncheckedWidget14(),
'/GeneratedTextboxuncheckedWidget15': (context) =>
GeneratedTextboxuncheckedWidget15(),
'/GeneratedTextboxuncheckedWidget16': (context) =>
GeneratedTextboxuncheckedWidget16(),
'/GeneratedTextboxuncheckedWidget17': (context) =>
GeneratedTextboxuncheckedWidget17(),
'/GeneratedTextboxuncheckedWidget18': (context) =>
GeneratedTextboxuncheckedWidget18(),
'/GeneratedTextboxuncheckedWidget19': (context) =>
GeneratedTextboxuncheckedWidget19(),
'/GeneratedTextWidget2': (context) => GeneratedTextWidget2(),
'/GeneratedTextboxuncheckedWidget20': (context) =>
GeneratedTextboxuncheckedWidget20(),
'/GeneratedTextWidget3': (context) => GeneratedTextWidget3(),
'/GeneratedComponent4Widget1': (context) => GeneratedComponent4Widget1(),
'/GeneratedComponent7Widget1': (context) => GeneratedComponent7Widget1(),
'/GeneratedComponent5Widget1': (context) => GeneratedComponent5Widget1(),
'/GeneratedComponent6Widget3': (context) => GeneratedComponent6Widget3(),
'/GeneratedEllipse98Widget282': (context) => GeneratedEllipse98Widget282(),
'/GeneratedCheck_circleWidget': (context) => GeneratedCheck_circleWidget(),
'/GeneratedCheck_circleWidget1': (context) => GeneratedCheck_circleWidget1(),
'/GeneratedTEXTBARWidget15': (context) => GeneratedTEXTBARWidget15(),
'/GeneratedTEXTBARWidget16': (context) => GeneratedTEXTBARWidget16(),
'/GeneratedTEXTBARWidget17': (context) => GeneratedTEXTBARWidget17(),
'/GeneratedTEXTBARWidget18': (context) => GeneratedTEXTBARWidget18(),
'/GeneratedTEXTBARWidget19': (context) => GeneratedTEXTBARWidget19(),
'/GeneratedTEXTBARWidget20': (context) => GeneratedTEXTBARWidget20(),
'/GeneratedTEXTBARWidget21': (context) => GeneratedTEXTBARWidget21(),
'/GeneratedTEXTBARWidget22': (context) => GeneratedTEXTBARWidget22(),
'/GeneratedTEXTBARWidget23': (context) => GeneratedTEXTBARWidget23(),
'/GeneratedTEXTBARWidget24': (context) => GeneratedTEXTBARWidget24(),
'/GeneratedTEXTBARWidget25': (context) => GeneratedTEXTBARWidget25(),
},
);
}
}
Try removing this line from your code-
onGenerateRoute:generateRoute,
Also add this route in your routes section -
/GeneratedAndroid1Widget.
It should work fine then.
I am using zendframework3 with nginad on ubuntu16, the index page is showing, but when I click on signup, add publisher etc. It couldn't find the route. I looked at the folder structure and configuration files as well as views it's there, but couldn't find out what's wrong. Here is the path:
/signup/customer
/signup/newuser
/auth/login
/company
/legal
Here is the configure file for DashboardManager module:
<?php
return array(
'router' => array(
'routes' => array(
'websites' => array(
'type' => 'segment',
'options' => array(
'route' =>
'/websites[/[:action[/[:param1[/]]]]]',
'defaults' => array(
'controller' =>
'DashboardManager\Controller\Website',
'action' => 'index',
),
),
),
'users' => array(
'type' => 'segment',
'options' => array(
'route' => '/users[/[:action[/[:param1[/]]]]]',
'defaults' => array(
'controller' =>
'DashboardManager\Controller\Signup',
'action' => 'account',
),
),
),
'pxsspdirectory' => array(
'type' => 'segment',
'options' => array(
'route' =>
'/directory[/[:action[/[:param1[/]]]]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' =>
'DashboardManager\Controller',
'controller' =>
'DashboardManager\Controller\Services',
'action' => 'ssp',
),
),
),
'pxpublishers' => array(
'type' => 'segment',
'options' => array(
'route' => '/private-
exchange/publishers/websites[/]',
'defaults' => array(
'controller' =>
'DashboardManager\Controller\Publisher',
'action' => 'pxpublishers',
),
),
),
'pxpublisherslist' => array(
'type' => 'segment',
'options' => array(
'route' => '/private-
exchange/websites/list/[:param1[/]]',
'defaults' => array(
'controller' =>
'DashboardManager\Controller\Website',
'action' => 'pxlist',
),
),
),
'pxwebsitelist' => array(
'type' => 'segment',
'options' => array(
'route' => '/private-
exchange/publisher/websites[/]',
'defaults' => array(
'controller' => '
DashboardManager\Controller\Website',
'action' => 'pxwebsitelist',
),
),
),
'pxnewpublisher' => array(
'type' => 'segment',
'options' => array(
'route' => '/private-
exchange/publishers/add[/]',
'defaults' => array(
'controller' =>
'DashboardManager\Controller\Signup',
'action' => 'pxnewpublisher',
),
),
),
'pxloginaspublisher' => array(
'type' => 'segment',
'options' => array(
'route' => '/private-
exchange/publishers/loginasdomain[/]',
'defaults' => array(
'controller' =>
'DashboardManager\Controller\Publisher',
'action' => 'loginasdomain',
),
),
),
'pxpublisherlist' => array(
'type' => 'segment',
'options' => array(
'route' => '/private-
exchange/publishers/list[/]',
'defaults' => array(
'controller' =>
'DashboardManager\Controller\Signup',
'action' => 'publishersdomain',
),
),
),
'pxnewpublisheradd' => array(
'type' => 'segment',
'options' => array(
'route' => '/private-
exchange/publishers/new[/]',
'defaults' => array(
'__NAMESPACE__' =>
'DashboardManager\Controller',
'controller' =>
'DashboardManager\Controller\Signup',
'action' => 'pxnewuser',
),
),
),
'company' => array(
'type' => 'segment',
'options' => array(
'route' => '/company',
'defaults' => array(
'controller' =>
'DashboardManager\Controller\Company',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'action' => array(
'type' => 'segment',
'options' => array(
'route' => '/:action',
'constraints' => array(
//'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Company',
'action' => 'index',
),
),
),
'press' => array(
'type' => 'segment',
'options' => array(
'route' => '/press/releases/:param1',
'constraints' => array(
//'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Company',
'action' => 'pressinner',
),
),
),
'jobs' => array(
'type' => 'segment',
'options' => array(
'route' => '/jobs/post/:param1',
'constraints' => array(
//'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Company',
'action' => 'jobsinner',
),
),
),
'jobform' => array(
'type' => 'segment',
'options' => array(
'route' => '/jobs/post/apply/:param1',
'constraints' => array(
//'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Company',
'action' => 'jobform',
),
),
),
),
),
'signup' => array(
'type' => 'segment',
'options' => array(
'route' => '/signup[/[:action[/[:param1[/]]]]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Signup',
'action' => 'index',
),
),
),
'signup-index' => array(
'type' => 'segment',
'options' => array(
'route' => '/',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Signup',
'action' => 'index',
),
),
),
'manager' => array(
'type' => 'segment',
'options' => array(
'route' => '/manager[/[:action[/[:param1[/]]]]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Manager',
'action' => 'index',
),
),
),
'report' => array(
'type' => 'segment',
'options' => array(
'route' => '/report[/[:action[/[:param1[/]]]]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Report',
'action' => 'index',
),
),
),
'private-exchange' => array(
'type' => 'segment',
'options' => array(
'route' => '/private-exchange[/[:action[/[:param1[/]]]]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Demand',
'action' => 'index',
),
),
),
'publisher' => array(
'type' => 'Literal',
'options' => array(
'route' => '/publisher',
'defaults' => array(
'controller' => 'DashboardManager\Controller\Publisher',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'process' => array(
'type' => 'segment',
'options' => array(
'route' => '/[:action[/[:param1[/]]]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Publisher',
'action' => 'index',
),
),
),
'zone' => array(
'type' => 'segment',
'options' => array(
'route' => '/zone/:param1[/[:action[/[:id[/]]]]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'param1' => '[0-9]+',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'DashboardManager\Controller',
'controller' => 'DashboardManager\Controller\Zone',
'action' => 'index',
),
),
),
),
),
'login' => array(
'type' => 'Literal',
'options' => array(
'route' => '/auth',
'defaults' => array(
'controller' => 'DashboardManager\Controller\Auth',
'action' => 'login',
),
),
'may_terminate' => true,
'child_routes' => array(
'process' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:action]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
'msa' => array(
'type' => 'segment',
'options' => array(
'route' => '/auth/msa[/[:param1[/]]]',
'constraints' => array(
'param1' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'DashboardManager\Controller\Auth',
'action' => 'msa',
),
),
),
),
),
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'Zend\Authentication\AuthenticationService' => function($sm) {
//return new Zend\Authentication\AuthenticationService(); // Built-in ZF2 Authentication Service.
return $sm->get('AuthService'); // Custom Authentication Service.
},
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'DashboardManager\Controller\Company' => 'DashboardManager\Controller\CompanyController',
'DashboardManager\Controller\Signup' => 'DashboardManager\Controller\SignupController',
'DashboardManager\Controller\Manager' => 'DashboardManager\Controller\ManagerController',
'DashboardManager\Controller\Demand' => 'DashboardManager\Controller\DemandController',
'DashboardManager\Controller\Publisher' => 'DashboardManager\Controller\PublisherController',
'DashboardManager\Controller\Auth' => 'DashboardManager\Controller\AuthController',
'DashboardManager\Controller\Success' => 'DashboardManager\Controller\SuccessController',
'DashboardManager\Controller\Report' => 'DashboardManager\Controller\ReportController',
'DashboardManager\Controller\Zone' => 'DashboardManager\Controller\ZoneController',
'DashboardManager\Controller\Website' => 'DashboardManager\Controller\WebsiteController',
'DashboardManager\Controller\Services' => 'DashboardManager\Controller\ServicesController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'unauthorized_template' => __DIR__ . '/../view/error/403.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
// 'manager' => __DIR__ . '/../view',
// 'private-exchange' => __DIR__ . '/../view',
),
)
);
?>