Browse Source

add routes

fish 8 months ago
parent
commit
05b13e84ba
4 changed files with 24 additions and 14 deletions
  1. 2 10
      README.md
  2. 4 4
      lib/main.dart
  3. 16 0
      lib/routes.dart
  4. 2 0
      pubspec.yaml

+ 2 - 10
README.md

@@ -2,15 +2,7 @@
 
 flutter web项目的打包成app
 
-## Getting Started
+## License
 
-This project is a starting point for a Flutter application.
+## Reference
 
-A few resources to get you started if this is your first Flutter project:
-
-- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
-- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
-
-For help getting started with Flutter development, view the
-[online documentation](https://docs.flutter.dev/), which offers tutorials,
-samples, guidance on mobile development, and a full API reference.

+ 4 - 4
lib/main.dart

@@ -1,6 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
-import 'package:web_package/pages/home_page.dart';
+import 'package:web_package/routes.dart';
 
 /// Description: enter point
 /// Time       : 01/23/2024 Tuesday
@@ -17,20 +17,20 @@ void main() {
 }
 
 class MyApp extends StatelessWidget {
-  
   const MyApp({super.key});
 
   // This widget is the root of your application.
   @override
   Widget build(BuildContext context) {
     return MaterialApp(
-      title: 'Flutter Demo',
+      title: 'web package',
       debugShowCheckedModeBanner: false,
       theme: ThemeData(
         colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
         useMaterial3: true,
       ),
-      home: const HomePage(),
+      initialRoute: Routes.home,
+      onGenerateRoute: Routes.onGenerateRoute,
     );
   }
 }

+ 16 - 0
lib/routes.dart

@@ -0,0 +1,16 @@
+import 'package:flutter/material.dart';
+import 'package:web_package/pages/home_page.dart';
+
+class Routes {
+  static const String index = "/";
+  static const String home = "/home";
+
+  static Route onGenerateRoute(RouteSettings settings) {
+    switch (settings.name) {
+      case home:
+        return MaterialPageRoute(builder: (_) => const HomePage());
+      default:
+        return MaterialPageRoute(builder: (_) => const HomePage());
+    }
+  }
+}

+ 2 - 0
pubspec.yaml

@@ -10,10 +10,12 @@ dependencies:
   cupertino_icons: ^1.0.5
   webview_flutter: ^4.0.1
   get: ^4.6.5
+
 dev_dependencies:
   flutter_test:
     sdk: flutter
   flutter_lints: ^2.0.0
+  
 flutter:
 
   uses-material-design: true