'Flutter Web Handling URLs
I have a website. In the future there will be thousands of pages. And i don't know how to handle all pages for best navigation. I created 2 classes as shown in below.
class RoutePaths {
static const Homepage = '/';
static const Calculations = '/calculations';
static const MathCalculations = '/calculations/math-calculation';
static const PhysicsCalculations =
'/calculations/physics-calculation';
}
class RouteGenerator {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case RoutePaths.Homepage:
return MaterialPageRoute(
settings: settings,
builder: (_) => const Homepage(),
);
case RoutePaths.Calculations:
return MaterialPageRoute(
settings: settings,
builder: (_) => const Calculations(),
);
case RoutePaths.MathCalculations:
return MaterialPageRoute(
settings: settings,
builder: (_) => const MathCalculations(),
);
case RoutePaths.PhysicsCalculations:
return MaterialPageRoute(
settings: settings,
builder: (_) => const PhysicsCalculations(),
);
default:
return MaterialPageRoute(
settings: settings,
builder: (_) => const Homepage(),
);
}
}
In the first class there are static names of pages. In the second class there are navigations. If there will be 10.000 pages then i should create 10.000 static names in the first class? If yes, i think this is big load for the website. And if i don't use static variables, i have to copy paste route names to use in different classes and when i want to change route names, it will be very hard. And similarly 10000 lines for navigation is also much. What is the best solution for big projects?
Solution 1:[1]
Create other class which contain list of all class widgets constructor
Then just access this from other class is very best thing
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jay |
