refactor: use go_router

This commit is contained in:
Rongjian Zhang 2022-09-12 01:54:07 +08:00
parent dc40206576
commit 3261db8fee
8 changed files with 863 additions and 754 deletions

View File

@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:git_touch/home.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/theme.dart'; import 'package:git_touch/models/theme.dart';
import 'package:provider/provider.dart'; import 'package:git_touch/router.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:intl/locale.dart' as l; import 'package:intl/locale.dart' as l;
import 'package:provider/provider.dart';
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@override @override
@ -49,14 +49,19 @@ class MyApp extends StatelessWidget {
return Container( return Container(
key: auth.rootKey, key: auth.rootKey,
child: theme.theme == AppThemeType.cupertino child: theme.theme == AppThemeType.cupertino
? CupertinoApp( ? CupertinoApp.router(
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
theme: CupertinoThemeData(brightness: theme.brightness), theme: CupertinoThemeData(brightness: theme.brightness),
home: Home(),
localizationsDelegates: AppLocalizations.localizationsDelegates, localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales, supportedLocales: AppLocalizations.supportedLocales,
localeListResolutionCallback: localeListResolutionCallback, localeListResolutionCallback: localeListResolutionCallback,
) )
: MaterialApp( : MaterialApp.router(
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
theme: ThemeData( theme: ThemeData(
brightness: theme.brightness, brightness: theme.brightness,
primaryColor: primaryColor:
@ -66,9 +71,10 @@ class MyApp extends StatelessWidget {
builders: { builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(), TargetPlatform.android: ZoomPageTransitionsBuilder(),
}, },
), colorScheme: ColorScheme.fromSwatch().copyWith(secondary: theme.palette.primary), ),
colorScheme: ColorScheme.fromSwatch()
.copyWith(secondary: theme.palette.primary),
), ),
home: Home(),
localizationsDelegates: AppLocalizations.localizationsDelegates, localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales, supportedLocales: AppLocalizations.supportedLocales,
localeListResolutionCallback: localeListResolutionCallback, localeListResolutionCallback: localeListResolutionCallback,

View File

@ -1,33 +1,33 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/notification.dart'; import 'package:git_touch/models/notification.dart';
import 'package:git_touch/models/theme.dart'; import 'package:git_touch/models/theme.dart';
import 'package:git_touch/screens/bb_explore.dart'; import 'package:git_touch/screens/bb_explore.dart';
import 'package:git_touch/screens/bb_teams.dart'; import 'package:git_touch/screens/bb_teams.dart';
import 'package:git_touch/screens/bb_user.dart'; import 'package:git_touch/screens/bb_user.dart';
import 'package:git_touch/screens/ge_search.dart';
import 'package:git_touch/screens/ge_user.dart'; import 'package:git_touch/screens/ge_user.dart';
import 'package:git_touch/screens/gh_news.dart';
import 'package:git_touch/screens/gh_notification.dart';
import 'package:git_touch/screens/gh_search.dart';
import 'package:git_touch/screens/gh_trending.dart';
import 'package:git_touch/screens/gh_user.dart';
import 'package:git_touch/screens/gl_explore.dart';
import 'package:git_touch/screens/gl_groups.dart';
import 'package:git_touch/screens/gl_search.dart'; import 'package:git_touch/screens/gl_search.dart';
import 'package:git_touch/screens/gl_user.dart';
import 'package:git_touch/screens/go_search.dart'; import 'package:git_touch/screens/go_search.dart';
import 'package:git_touch/screens/go_user.dart'; import 'package:git_touch/screens/go_user.dart';
import 'package:git_touch/screens/gt_orgs.dart'; import 'package:git_touch/screens/gt_orgs.dart';
import 'package:git_touch/screens/gt_user.dart'; import 'package:git_touch/screens/gt_user.dart';
import 'package:git_touch/screens/gl_explore.dart';
import 'package:git_touch/screens/gl_groups.dart';
import 'package:git_touch/screens/gl_user.dart';
import 'package:git_touch/screens/login.dart'; import 'package:git_touch/screens/login.dart';
import 'package:git_touch/screens/gh_notification.dart';
import 'package:git_touch/screens/gh_user.dart';
import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/utils/utils.dart';
import 'package:github/github.dart';
import 'package:launch_review/launch_review.dart'; import 'package:launch_review/launch_review.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:git_touch/screens/gh_news.dart';
import 'package:git_touch/screens/gh_search.dart';
import 'package:git_touch/screens/gh_trending.dart';
import 'package:git_touch/screens/ge_search.dart';
import 'package:github/github.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:pub_semver/pub_semver.dart'; import 'package:pub_semver/pub_semver.dart';
import 'package:universal_io/io.dart'; import 'package:universal_io/io.dart';

View File

@ -1,14 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:git_touch/app.dart'; import 'package:git_touch/app.dart';
import 'package:git_touch/models/code.dart';
import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/code.dart';
import 'package:git_touch/models/notification.dart';
import 'package:git_touch/models/theme.dart'; import 'package:git_touch/models/theme.dart';
import 'package:git_touch/router.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:git_touch/models/notification.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/services.dart';
import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/sentry_flutter.dart';
void main() async { void main() async {
@ -31,34 +29,6 @@ void main() async {
codeModel.init(), codeModel.init(),
]); ]);
for (var screen in CommonRouter.routes) {
themeModel.router.define(CommonRouter.prefix + screen.path,
handler: Handler(handlerFunc: screen.handler));
}
for (var screen in GitlabRouter.routes) {
themeModel.router.define(GitlabRouter.prefix + screen.path,
handler: Handler(handlerFunc: screen.handler));
}
for (var screen in GiteaRouter.routes) {
themeModel.router.define(GiteaRouter.prefix + screen.path,
handler: Handler(handlerFunc: screen.handler));
}
for (var screen in BitbucketRouter.routes) {
themeModel.router.define(BitbucketRouter.prefix + screen.path,
handler: Handler(handlerFunc: screen.handler));
}
for (var screen in GithubRouter.routes) {
themeModel.router.define(GithubRouter.prefix + screen.path,
handler: Handler(handlerFunc: screen.handler));
}
for (var screen in GiteeRouter.routes) {
themeModel.router.define(GiteeRouter.prefix + screen.path,
handler: Handler(handlerFunc: screen.handler));
}
for (var screen in GogsRouter.routes) {
themeModel.router.define(GogsRouter.prefix + screen.path,
handler: Handler(handlerFunc: screen.handler));
}
// To match status bar color to app bar color // To match status bar color to app bar color
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: Colors.transparent, statusBarColor: Colors.transparent,

View File

@ -1,15 +1,16 @@
import 'package:universal_io/io.dart';
import 'dart:async'; import 'dart:async';
import 'package:fimber/fimber.dart'; import 'package:fimber/fimber.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/action_button.dart';
import 'package:primer/primer.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/S.dart'; import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/action_button.dart';
import 'package:go_router/go_router.dart';
import 'package:primer/primer.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:universal_io/io.dart';
class AppThemeType { class AppThemeType {
static const material = 0; static const material = 0;
@ -177,8 +178,6 @@ class ThemeModel with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
final router = FluroRouter();
final paletteLight = Palette( final paletteLight = Palette(
primary: PrimerColors.blue500, primary: PrimerColors.blue500,
text: Colors.black, text: Colors.black,
@ -250,14 +249,11 @@ class ThemeModel with ChangeNotifier {
push(BuildContext context, String url, {bool replace = false}) { push(BuildContext context, String url, {bool replace = false}) {
// Fimber.d(url); // Fimber.d(url);
if (url.startsWith('/')) { if (url.startsWith('/')) {
return router.navigateTo( if (replace) {
context, context.replace(url);
url, } else {
transition: theme == AppThemeType.cupertino context.push(url);
? TransitionType.cupertino }
: TransitionType.material,
replace: replace,
);
} else { } else {
launchStringUrl(url); launchStringUrl(url);
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,16 @@
import 'package:ferry/ferry.dart'; import 'package:ferry/ferry.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:git_touch/graphql/__generated__/github.data.gql.dart'; import 'package:git_touch/graphql/__generated__/github.data.gql.dart';
import 'package:git_touch/graphql/__generated__/github.req.gql.dart'; import 'package:git_touch/graphql/__generated__/github.req.gql.dart';
import 'package:git_touch/graphql/__generated__/github.var.gql.dart'; import 'package:git_touch/graphql/__generated__/github.var.gql.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart'; import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/widgets/app_bar_title.dart'; import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/object_tree.dart'; import 'package:git_touch/widgets/object_tree.dart';
import 'package:git_touch/widgets/table_view.dart'; import 'package:git_touch/widgets/table_view.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:git_touch/models/auth.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
class GhGistsFilesScreen extends StatelessWidget { class GhGistsFilesScreen extends StatelessWidget {
final String id; final String id;

View File

@ -260,13 +260,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.1" version: "1.0.1"
fluro:
dependency: "direct main"
description:
name: fluro
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -350,6 +343,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
go_router:
dependency: "direct main"
description:
name: go_router
url: "https://pub.dartlang.org"
source: hosted
version: "4.4.1"
google_fonts: google_fonts:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -37,7 +37,6 @@ dependencies:
file_icon: file_icon:
filesize: filesize:
fimber: fimber:
fluro:
flutter_highlight: flutter_highlight:
flutter_markdown: flutter_markdown:
flutter_svg: flutter_svg:
@ -67,6 +66,7 @@ dependencies:
sentry_flutter: sentry_flutter:
pub_semver: pub_semver:
google_fonts: google_fonts:
go_router:
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: