From 56352389217c7c4990f1828c51184e149cc9723e Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Wed, 7 Sep 2022 00:32:56 +0800 Subject: [PATCH] style: dart fix apply --- lib/app.dart | 6 +++--- lib/home.dart | 34 +++++++++++++++++----------------- lib/scaffolds/long_list.dart | 20 +++++++++----------- lib/screens/bb_user.dart | 14 +++++++------- lib/screens/gl_search.dart | 14 +++++++------- lib/screens/gl_user.dart | 10 +++++----- lib/widgets/label.dart | 12 ++++++------ 7 files changed, 54 insertions(+), 56 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 7f5f5d1..e2b36e6 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -13,6 +13,7 @@ class MyApp extends StatelessWidget { final auth = Provider.of(context); final theme = Provider.of(context); + // ignore: prefer_function_declarations_over_variables final LocaleListResolutionCallback localeListResolutionCallback = (locales, supportedLocales) { // 1. user set locale @@ -60,13 +61,12 @@ class MyApp extends StatelessWidget { brightness: theme.brightness, primaryColor: theme.brightness == Brightness.dark ? null : Colors.white, - accentColor: theme.palette.primary, scaffoldBackgroundColor: theme.palette.background, - pageTransitionsTheme: PageTransitionsTheme( + pageTransitionsTheme: const PageTransitionsTheme( builders: { TargetPlatform.android: ZoomPageTransitionsBuilder(), }, - ), + ), colorScheme: ColorScheme.fromSwatch().copyWith(secondary: theme.palette.primary), ), home: Home(), localizationsDelegates: AppLocalizations.localizationsDelegates, diff --git a/lib/home.dart b/lib/home.dart index 1157974..a156aa4 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -47,7 +47,7 @@ class _HomeState extends State { @override initState() { super.initState(); - Future.delayed(Duration(seconds: 5), () async { + Future.delayed(const Duration(seconds: 5), () async { final latest = await GitHub() .repositories .getLatestRelease(RepositorySlug.full('git-touch/git-touch')); @@ -57,7 +57,7 @@ class _HomeState extends State { .compareTo(Version.parse(current)) == 1) { final res = await context.read().showConfirm(context, - Text('New version released. Would you like to download it?')); + const Text('New version released. Would you like to download it?')); if (res == true) { if (Platform.isIOS) { // go to app store @@ -103,7 +103,7 @@ class _HomeState extends State { case 2: return GlSearchScreen(); case 3: - return GlUserScreen(null); + return const GlUserScreen(null); } break; case PlatformType.bitbucket: @@ -113,13 +113,13 @@ class _HomeState extends State { case 1: return BbTeamsScreen(); case 2: - return BbUserScreen(null); + return const BbUserScreen(null); } break; case PlatformType.gitea: switch (index) { case 0: - return GtOrgsScreen(); + return const GtOrgsScreen(); case 1: return GtUserScreen(auth.activeAccount!.login, isViewer: true); } @@ -180,23 +180,23 @@ class _HomeState extends State { List _buildNavigationItems(String platform) { final search = BottomNavigationBarItem( - icon: Icon(Ionicons.search_outline), - activeIcon: Icon(Ionicons.search), + icon: const Icon(Ionicons.search_outline), + activeIcon: const Icon(Ionicons.search), label: AppLocalizations.of(context)!.search, ); final group = BottomNavigationBarItem( - icon: Icon(Ionicons.people_outline), - activeIcon: Icon(Ionicons.people), + icon: const Icon(Ionicons.people_outline), + activeIcon: const Icon(Ionicons.people), label: AppLocalizations.of(context)!.organizations, ); final me = BottomNavigationBarItem( - icon: Icon(Ionicons.person_outline), - activeIcon: Icon(Ionicons.person), + icon: const Icon(Ionicons.person_outline), + activeIcon: const Icon(Ionicons.person), label: AppLocalizations.of(context)!.me, ); final explore = BottomNavigationBarItem( - icon: Icon(Ionicons.compass_outline), - activeIcon: Icon(Ionicons.compass), + icon: const Icon(Ionicons.compass_outline), + activeIcon: const Icon(Ionicons.compass), label: AppLocalizations.of(context)!.explore, ); @@ -204,8 +204,8 @@ class _HomeState extends State { case PlatformType.github: return [ BottomNavigationBarItem( - icon: Icon(Ionicons.newspaper_outline), - activeIcon: Icon(Ionicons.newspaper), + icon: const Icon(Ionicons.newspaper_outline), + activeIcon: const Icon(Ionicons.newspaper), label: AppLocalizations.of(context)!.news, ), BottomNavigationBarItem( @@ -215,8 +215,8 @@ class _HomeState extends State { label: AppLocalizations.of(context)!.notification, ), BottomNavigationBarItem( - icon: Icon(Ionicons.flame_outline), - activeIcon: Icon(Ionicons.flame), + icon: const Icon(Ionicons.flame_outline), + activeIcon: const Icon(Ionicons.flame), label: AppLocalizations.of(context)!.trending, ), search, diff --git a/lib/scaffolds/long_list.dart b/lib/scaffolds/long_list.dart index 63f352b..f7c29b9 100644 --- a/lib/scaffolds/long_list.dart +++ b/lib/scaffolds/long_list.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter/widgets.dart'; import 'package:git_touch/models/theme.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:provider/provider.dart'; @@ -36,7 +35,7 @@ class LongListStatefulScaffold extends StatefulWidget { final Future> Function() onRefresh; final Future> Function(String? cursor) onLoadMore; - LongListStatefulScaffold({ + const LongListStatefulScaffold({ required this.title, this.trailingBuilder, required this.headerBuilder, @@ -74,7 +73,7 @@ class _LongListStatefulScaffoldState payload = await widget.onRefresh(); } catch (err) { error = err.toString(); - throw err; + rethrow; } finally { if (mounted) { setState(() { @@ -90,11 +89,10 @@ class _LongListStatefulScaffoldState loadingMore = true; }); try { - LongListPayload _payload = - await widget.onLoadMore(payload!.cursor); - payload!.totalCount = _payload.totalCount; - payload!.cursor = _payload.cursor; - payload!.leadingItems.addAll(_payload.leadingItems); + LongListPayload p = await widget.onLoadMore(payload!.cursor); + payload!.totalCount = p.totalCount; + payload!.cursor = p.cursor; + payload!.leadingItems.addAll(p.leadingItems); } finally { if (mounted) { setState(() { @@ -134,9 +132,9 @@ class _LongListStatefulScaffoldState Text('$count hidden items', style: TextStyle(color: theme.palette.text, fontSize: 15)), - Padding(padding: EdgeInsets.only(top: 4)), + const Padding(padding: EdgeInsets.only(top: 4)), loadingMore - ? CupertinoActivityIndicator() + ? const CupertinoActivityIndicator() : Text( 'Load more...', style: TextStyle( @@ -168,7 +166,7 @@ class _LongListStatefulScaffoldState child: ErrorReload(text: error, onTap: _refresh)); } else if (loading) { // TODO: - return SliverToBoxAdapter(child: Loading(more: false)); + return const SliverToBoxAdapter(child: Loading(more: false)); } else { return SliverList( delegate: diff --git a/lib/screens/bb_user.dart b/lib/screens/bb_user.dart index 74a10ea..08f736a 100644 --- a/lib/screens/bb_user.dart +++ b/lib/screens/bb_user.dart @@ -13,14 +13,14 @@ import 'package:git_touch/utils/utils.dart'; class BbUserScreen extends StatelessWidget { final String? login; final bool isTeam; - BbUserScreen(this.login, {this.isTeam = false}); + const BbUserScreen(this.login, {this.isTeam = false}); bool get isViewer => login == null; @override Widget build(BuildContext context) { final auth = Provider.of(context); - final _accountId = auth.activeAccount!.accountId; - final _login = login ?? auth.activeAccount!.login; + final accountId = auth.activeAccount!.accountId; + final finalLogin = login ?? auth.activeAccount!.login; return RefreshStatefulScaffold>>( title: Text(isViewer ? 'Me' @@ -30,16 +30,16 @@ class BbUserScreen extends StatelessWidget { fetch: () async { final res = await Future.wait([ auth - .fetchBbJson('/${isTeam ? 'teams' : 'users'}/$_accountId') + .fetchBbJson('/${isTeam ? 'teams' : 'users'}/$accountId') .then((value) => BbUser.fromJson(value)), auth - .fetchBbWithPage('/repositories/$_login') + .fetchBbWithPage('/repositories/$finalLogin') .then((value) => [for (var v in value.items) BbRepo.fromJson(v)]), ]); return Tuple2(res[0] as BbUser, res[1] as Iterable); }, action: isViewer - ? ActionEntry( + ? const ActionEntry( iconData: Ionicons.cog, url: '/settings', ) @@ -50,7 +50,7 @@ class BbUserScreen extends StatelessWidget { return Column( children: [ UserHeader( - login: _login, + login: finalLogin, avatarUrl: user.avatarUrl, name: user.displayName, createdAt: user.createdOn, diff --git a/lib/screens/gl_search.dart b/lib/screens/gl_search.dart index 66e39bc..95eebb5 100644 --- a/lib/screens/gl_search.dart +++ b/lib/screens/gl_search.dart @@ -70,7 +70,7 @@ class _GlSearchScreenState extends State { color: theme.palette.background, child: CupertinoTextField( prefix: Row( - children: [ + children: const [ SizedBox(width: 8), Icon(Octicons.search, size: 20, color: PrimerColors.gray400), ], @@ -104,16 +104,16 @@ class _GlSearchScreenState extends State { static const tabs = ['Projects', 'Users']; - Widget _buildItem(_p) { + Widget _buildItem(project) { if (_activeTab == 0) { - final p = _p as GitlabProject; + final p = project as GitlabProject; final updatedAt = timeago.format(p.lastActivityAt!); return RepositoryItem.gl( payload: p, note: 'Updated $updatedAt', ); } else { - final p = _p as GitlabUser; + final p = project as GitlabUser; return UserItem.gitlab( login: p.username, name: p.name, @@ -136,7 +136,7 @@ class _GlSearchScreenState extends State { if (theme == AppThemeType.cupertino) Center( child: Padding( - padding: EdgeInsets.symmetric(vertical: 8), + padding: const EdgeInsets.symmetric(vertical: 8), child: CupertinoSlidingSegmentedControl( groupValue: _activeTab, onValueChanged: _onTabSwitch, @@ -144,13 +144,13 @@ class _GlSearchScreenState extends State { key, Padding( padding: const EdgeInsets.symmetric(horizontal: 8), - child: Text(text, style: TextStyle(fontSize: 14)), + child: Text(text, style: const TextStyle(fontSize: 14)), ))), ), ), ), if (_loading) - Loading() + const Loading() else if (_activeTab == 0) ..._projects.map(_buildItem).toList() else diff --git a/lib/screens/gl_user.dart b/lib/screens/gl_user.dart index 815c4ba..0e1c97a 100644 --- a/lib/screens/gl_user.dart +++ b/lib/screens/gl_user.dart @@ -14,7 +14,7 @@ import 'package:flutter_gen/gen_l10n/S.dart'; class GlUserScreen extends StatelessWidget { final int? id; - GlUserScreen(this.id); + const GlUserScreen(this.id); bool get isViewer => id == null; @override @@ -25,10 +25,10 @@ class GlUserScreen extends StatelessWidget { : AppLocalizations.of(context)!.user), fetch: () async { final auth = context.read(); - final _id = id ?? auth.activeAccount!.gitlabId; + final finalId = id ?? auth.activeAccount!.gitlabId; final res = await Future.wait([ - auth.fetchGitlab('/users/$_id'), - auth.fetchGitlab('/users/$_id/projects'), + auth.fetchGitlab('/users/$finalId'), + auth.fetchGitlab('/users/$finalId/projects'), ]); return Tuple2( GitlabUser.fromJson(res[0]), @@ -36,7 +36,7 @@ class GlUserScreen extends StatelessWidget { ); }, action: isViewer - ? ActionEntry( + ? const ActionEntry( iconData: Ionicons.cog, url: '/settings', ) diff --git a/lib/widgets/label.dart b/lib/widgets/label.dart index f35db92..deb7dc0 100644 --- a/lib/widgets/label.dart +++ b/lib/widgets/label.dart @@ -7,7 +7,7 @@ class MyLabel extends StatelessWidget { final String? cssColor; final Color? textColor; - MyLabel({ + const MyLabel({ required this.name, this.color, this.cssColor, @@ -16,18 +16,18 @@ class MyLabel extends StatelessWidget { @override Widget build(BuildContext context) { - final _color = color ?? convertColor(cssColor); + final finalColor = color ?? convertColor(cssColor); return Container( - padding: EdgeInsets.symmetric(vertical: 2, horizontal: 6), + padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 6), decoration: BoxDecoration( - color: _color, - borderRadius: BorderRadius.all(Radius.circular(4)), + color: finalColor, + borderRadius: const BorderRadius.all(Radius.circular(4)), ), child: Text( name!, style: TextStyle( fontSize: 13, - color: textColor ?? getFontColorByBrightness(_color), + color: textColor ?? getFontColorByBrightness(finalColor), // fontWeight: FontWeight.w600, ), ),