style: dart fix apply

This commit is contained in:
Rongjian Zhang 2022-09-07 00:32:56 +08:00
parent 081acbeda8
commit 5635238921
7 changed files with 54 additions and 56 deletions

View File

@ -13,6 +13,7 @@ class MyApp extends StatelessWidget {
final auth = Provider.of<AuthModel>(context);
final theme = Provider.of<ThemeModel>(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,

View File

@ -47,7 +47,7 @@ class _HomeState extends State<Home> {
@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<Home> {
.compareTo(Version.parse(current)) ==
1) {
final res = await context.read<ThemeModel>().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<Home> {
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<Home> {
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<Home> {
List<BottomNavigationBarItem> _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<Home> {
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<Home> {
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,

View File

@ -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<T, K> extends StatefulWidget {
final Future<LongListPayload<T, K>> Function() onRefresh;
final Future<LongListPayload<T, K>> Function(String? cursor) onLoadMore;
LongListStatefulScaffold({
const LongListStatefulScaffold({
required this.title,
this.trailingBuilder,
required this.headerBuilder,
@ -74,7 +73,7 @@ class _LongListStatefulScaffoldState<T, K>
payload = await widget.onRefresh();
} catch (err) {
error = err.toString();
throw err;
rethrow;
} finally {
if (mounted) {
setState(() {
@ -90,11 +89,10 @@ class _LongListStatefulScaffoldState<T, K>
loadingMore = true;
});
try {
LongListPayload<T?, K> _payload =
await widget.onLoadMore(payload!.cursor);
payload!.totalCount = _payload.totalCount;
payload!.cursor = _payload.cursor;
payload!.leadingItems.addAll(_payload.leadingItems);
LongListPayload<T?, K> 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<T, K>
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<T, K>
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:

View File

@ -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<AuthModel>(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<Tuple2<BbUser, Iterable<BbRepo>>>(
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<BbRepo>);
},
action: isViewer
? ActionEntry(
? const ActionEntry(
iconData: Ionicons.cog,
url: '/settings',
)
@ -50,7 +50,7 @@ class BbUserScreen extends StatelessWidget {
return Column(
children: <Widget>[
UserHeader(
login: _login,
login: finalLogin,
avatarUrl: user.avatarUrl,
name: user.displayName,
createdAt: user.createdOn,

View File

@ -70,7 +70,7 @@ class _GlSearchScreenState extends State<GlSearchScreen> {
color: theme.palette.background,
child: CupertinoTextField(
prefix: Row(
children: <Widget>[
children: const <Widget>[
SizedBox(width: 8),
Icon(Octicons.search, size: 20, color: PrimerColors.gray400),
],
@ -104,16 +104,16 @@ class _GlSearchScreenState extends State<GlSearchScreen> {
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<GlSearchScreen> {
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<GlSearchScreen> {
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

View File

@ -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<AuthModel>();
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',
)

View File

@ -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,
),
),