Skip to content

Commit

Permalink
U 更新 由自定义路由切换为go_router,思路类似,但是团队维护插件,成熟
Browse files Browse the repository at this point in the history
U 更新 flutter版本支持提升到3.3.7
  • Loading branch information
Asscre committed Nov 8, 2022
1 parent c8a3af3 commit 079aece
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 142 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 31

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
Expand Down
12 changes: 4 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ssf/pages/index_page.dart';
import 'package:ssf/routes/custom_router.dart';
import 'package:ssf/routes/index_router.dart';

/// Author: Asscre
/// Editing time: 2020/11/12
void main() {
CustomRouter router = CustomRouter();
router.initRouters();

if (Platform.isAndroid) {
//设置Android头部的导航栏透明
SystemUiOverlayStyle systemUiOverlayStyle =
const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}

Expand All @@ -28,14 +24,14 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(
return MaterialApp.router(
title: 'SSF',
debugShowCheckedModeBanner: false,
routerConfig: IndexRouter.router,
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: const IndexPage(),
);
}
}
2 changes: 1 addition & 1 deletion lib/pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### 文件说明:
### 存放项目中的所有page页面
### author: Asscre
### time: 09-03-2021
### time: 11-08-2022
###

### 在这里你可以学会:
Expand Down
8 changes: 4 additions & 4 deletions lib/pages/home_pege.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:ssf/config/style.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ssf/config/style.dart';
import 'package:ssf/pages/use_dio/use_dio_page.dart';
import 'package:ssf/pages/use_provider/use_provider_page.dart';
import 'package:ssf/pages/use_router/use_router_page.dart';
Expand Down Expand Up @@ -37,21 +37,21 @@ class _HomePageState extends State<HomePage> {
label: '',
icon: Icon(
Icons.home_outlined,
size: 38.sp,
size: 28.sp,
),
),
BottomNavigationBarItem(
label: '',
icon: Icon(
Icons.chat_outlined,
size: 38.sp,
size: 28.sp,
),
),
BottomNavigationBarItem(
label: '',
icon: Icon(
Icons.privacy_tip_outlined,
size: 38.sp,
size: 28.sp,
),
),
];
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/index_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class _IndexPageState extends State<IndexPage> {
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
builder: () => const HomePage(),
builder: (BuildContext context, Widget? child) => const HomePage(),
);
}
}
8 changes: 4 additions & 4 deletions lib/pages/use_router/how_use_router_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ssf/config/style.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ssf/config/style.dart';

/// Congratulations on learning to use Router.
/// Reasonable route planning can make our project more clear.
Expand Down Expand Up @@ -33,15 +33,15 @@ class HowUseRouterPage extends StatelessWidget {
'恭喜你学会了使用Router。',
style: TextStyle(
color: Style.orange,
fontSize: 32.sp,
fontSize: 26.sp,
),
),
SizedBox(height: 30.h),
Text(
'合理规划路由可以使项目变得更加清晰明了。',
style: TextStyle(
color: Style.green,
fontSize: 20.sp,
fontSize: 18.sp,
),
),
SizedBox(height: 30.h),
Expand All @@ -53,7 +53,7 @@ class HowUseRouterPage extends StatelessWidget {
text: incParam,
style: TextStyle(
color: Style.red,
fontSize: 20.sp,
fontSize: 14.sp,
),
),
],
Expand Down
11 changes: 4 additions & 7 deletions lib/pages/use_router/use_router_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:ssf/routes/custom_router.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ssf/routes/routes_name.dart';
import 'package:go_router/go_router.dart';

/// Custom Router基本用法
class UseRouterPage extends StatelessWidget {
Expand Down Expand Up @@ -37,10 +35,9 @@ class UseRouterPage extends StatelessWidget {
/// 适当的抽离我们的组件,让整个页面更加的清晰
Widget _goToHowUseRouterPage(BuildContext context) {
return TextButton(
onPressed: () => CustomRouter.toPage(
context,
RoutesName.HowUseRouterPage,
arguments: 'This is param for AsscrePage',
onPressed: () => context.go(
'/HowUseRouterPage',
extra: 'This is param for AsscrePage',
),
child: Text(
'Click this to HowUseRouterPage',
Expand Down
8 changes: 2 additions & 6 deletions lib/routes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@
### 文件说明:
### 存放项目路由文件
### author: Asscre
### time: 09-03-2021
###

### CustomRouter: 路由跳转文件
### UseRouter: Use页面相关路由配置
### RoutesName: 所有路由地址集合
### time: 11-08-2022
###
75 changes: 0 additions & 75 deletions lib/routes/custom_router.dart

This file was deleted.

30 changes: 30 additions & 0 deletions lib/routes/index_router.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ssf/pages/index_page.dart';
import 'package:ssf/pages/use_router/how_use_router_page.dart';

class IndexRouter {
static GoRouter router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (
BuildContext context,
GoRouterState state,
) {
return const IndexPage();
},
routes: [
GoRoute(
path: 'HowUseRouterPage',
builder: (
BuildContext context,
GoRouterState state,
) =>
HowUseRouterPage(state.extra as String),
),
],
),
],
);
}
5 changes: 0 additions & 5 deletions lib/routes/routes_name.dart

This file was deleted.

7 changes: 0 additions & 7 deletions lib/routes/use_router.dart

This file was deleted.

Loading

0 comments on commit 079aece

Please sign in to comment.