refactor: replace material widgets

This commit is contained in:
Rongjian Zhang 2022-10-06 15:55:35 +08:00
parent 7b51747576
commit efd74ccd86
5 changed files with 105 additions and 102 deletions

View File

@ -1,5 +1,5 @@
import 'package:antd_mobile/antd_mobile.dart'; import 'package:antd_mobile/antd_mobile.dart';
import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart';
import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitee.dart'; import 'package:git_touch/models/gitee.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart'; import 'package:git_touch/scaffolds/refresh_stateful.dart';
@ -165,16 +165,18 @@ class GePullScreen extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Text( Text(
'+$additions', '+$additions',
style: const TextStyle( style: TextStyle(
color: Colors.green, color: AntTheme.of(context)
.colorSuccess,
fontSize: 15, fontSize: 15,
), ),
), ),
const SizedBox(width: 2), const SizedBox(width: 2),
Text( Text(
'-$deletions', '-$deletions',
style: const TextStyle( style: TextStyle(
color: Colors.red, color: AntTheme.of(context)
.colorDanger,
fontSize: 15, fontSize: 15,
), ),
), ),
@ -190,46 +192,42 @@ class GePullScreen extends StatelessWidget {
), ),
), ),
CommonStyle.border, CommonStyle.border,
ListTileTheme( Column(
contentPadding: EdgeInsets.zero, // title: Text(
child: ExpansionTile( // 'Commits',
title: Text( // style: TextStyle(
'Commits', // color: AntTheme.of(context).colorPrimary,
style: TextStyle( // fontSize: 18,
color: AntTheme.of(context).colorPrimary, // fontWeight: FontWeight.w600,
fontSize: 18, // ),
fontWeight: FontWeight.w600, // ),
), children: [
), for (var commit in commits) ...[
children: [ LinkWidget(
for (var commit in commits) ...[ url:
LinkWidget( '/gitee/$owner/$name/commits/${commit.sha}',
url: child: Container(
'/gitee/$owner/$name/commits/${commit.sha}', padding: const EdgeInsets.symmetric(
child: Container( vertical: 8),
padding: const EdgeInsets.symmetric( child: Row(
vertical: 8), mainAxisAlignment:
child: Row( MainAxisAlignment.spaceBetween,
mainAxisAlignment: children: <Widget>[
MainAxisAlignment.spaceBetween, Text(
children: <Widget>[ commit.sha!.substring(0, 7),
Text( style: TextStyle(
commit.sha!.substring(0, 7), color: AntTheme.of(context)
style: TextStyle( .colorPrimary,
color: AntTheme.of(context) fontSize: 17,
.colorPrimary, fontFamily: CommonStyle.monospace,
fontSize: 17,
fontFamily:
CommonStyle.monospace,
),
), ),
], ),
), ],
), ),
) ),
] )
], ]
), ],
), ),
], ],
), ),

View File

@ -9,8 +9,6 @@ import 'package:tuple/tuple.dart';
import 'package:universal_io/io.dart'; import 'package:universal_io/io.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
export 'package:flutter/material.dart'
show Card, ExpansionTile, IconButton; // TODO: remove
export 'package:flutter_vector_icons/flutter_vector_icons.dart' export 'package:flutter_vector_icons/flutter_vector_icons.dart'
show Octicons, Ionicons; show Octicons, Ionicons;

View File

@ -26,20 +26,23 @@ class FilesItem extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Provider.of<ThemeModel>(context); final theme = Provider.of<ThemeModel>(context);
final codeProvider = Provider.of<CodeModel>(context); final codeProvider = Provider.of<CodeModel>(context);
return Card( return AntCollapse(
color: AntTheme.of(context).colorBackground, activeKey: const [''],
margin: const EdgeInsets.all(0), onChange: (_) {
child: ExpansionTile( // TODO: set active
title: Text( },
filename!, panels: [
style: TextStyle( AntCollapsePanel(
color: AntTheme.of(context).colorPrimary, key: '',
fontSize: 18, title: Text(
fontWeight: FontWeight.w600, filename!,
style: TextStyle(
color: AntTheme.of(context).colorPrimary,
fontSize: 18,
fontWeight: FontWeight.w600,
),
), ),
), child: SingleChildScrollView(
children: <Widget>[
SingleChildScrollView(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
child: HighlightView( child: HighlightView(
patch!, patch!,
@ -51,8 +54,8 @@ class FilesItem extends StatelessWidget {
textStyle: codeProvider.fontStyle, textStyle: codeProvider.fontStyle,
), ),
), ),
], ),
), ],
); );
} }
} }

View File

@ -1,21 +1,22 @@
import 'package:antd_mobile/antd_mobile.dart'; import 'package:antd_mobile/antd_mobile.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.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/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/avatar.dart'; import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/markdown_view.dart'; import 'package:git_touch/widgets/markdown_view.dart';
import 'package:gql_github/releases.data.gql.dart'; import 'package:gql_github/releases.data.gql.dart';
import 'package:timeago/timeago.dart' as timeago; import 'package:timeago/timeago.dart' as timeago;
class ReleaseItem extends StatelessWidget { class ReleaseItem extends StatefulWidget {
const ReleaseItem( const ReleaseItem({
{required this.login, required this.login,
required this.publishedAt, required this.publishedAt,
required this.name, required this.name,
required this.tagName, required this.tagName,
required this.avatarUrl, required this.avatarUrl,
required this.description, required this.description,
this.releaseAssets}); this.releaseAssets,
});
final String? login; final String? login;
final DateTime? publishedAt; final DateTime? publishedAt;
final String? name; final String? name;
@ -24,6 +25,13 @@ class ReleaseItem extends StatelessWidget {
final String? description; final String? description;
final GReleasesData_repository_releases_nodes_releaseAssets? releaseAssets; final GReleasesData_repository_releases_nodes_releaseAssets? releaseAssets;
@override
State<ReleaseItem> createState() => _ReleaseItemState();
}
class _ReleaseItemState extends State<ReleaseItem> {
var _isExpanded = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
@ -32,7 +40,7 @@ class ReleaseItem extends StatelessWidget {
height: 12, height: 12,
), ),
Row(children: <Widget>[ Row(children: <Widget>[
Avatar(url: avatarUrl, size: AvatarSize.large), Avatar(url: widget.avatarUrl, size: AvatarSize.large),
const SizedBox(width: 10), const SizedBox(width: 10),
Expanded( Expanded(
child: Column( child: Column(
@ -42,7 +50,7 @@ class ReleaseItem extends StatelessWidget {
Row( Row(
children: <Widget>[ children: <Widget>[
Text( Text(
tagName!, widget.tagName!,
style: TextStyle( style: TextStyle(
color: AntTheme.of(context).colorPrimary, color: AntTheme.of(context).colorPrimary,
fontSize: 18, fontSize: 18,
@ -58,43 +66,36 @@ class ReleaseItem extends StatelessWidget {
fontSize: 16, fontSize: 16,
), ),
child: Text( child: Text(
'${login!} ${AppLocalizations.of(context)!.released} ${timeago.format(publishedAt!)}'), '${widget.login!} ${AppLocalizations.of(context)!.released} ${timeago.format(widget.publishedAt!)}'),
), ),
], ],
), ),
), ),
]), ]),
if (description != null && description!.isNotEmpty) ...[ if (widget.description != null && widget.description!.isNotEmpty) ...[
MarkdownFlutterView( MarkdownFlutterView(
description, widget.description,
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
], ],
Card( AntCollapse(
color: AntTheme.of(context).colorBox, activeKey: _isExpanded ? [''] : [],
margin: const EdgeInsets.all(0), onChange: (_) {
child: ExpansionTile( setState(() {
title: Text( _isExpanded = !_isExpanded;
'Assets (${releaseAssets?.nodes?.length ?? 0})', });
style: TextStyle( },
color: AntTheme.of(context).colorTextSecondary, panels: [
fontSize: 18, AntCollapsePanel(
fontWeight: FontWeight.w600, key: '',
), title:
), Text('Assets (${widget.releaseAssets?.nodes?.length ?? 0})'),
children: <Widget>[ child: AntList(
AntList(
children: [ children: [
if (releaseAssets != null) if (widget.releaseAssets != null)
for (var asset in releaseAssets!.nodes!) for (var asset in widget.releaseAssets!.nodes!)
AntListItem( AntListItem(
extra: IconButton( arrow: const Icon(Ionicons.download_outline),
onPressed: () {
context.pushUrl(asset.downloadUrl);
},
icon: const Icon(Ionicons.download_outline),
),
arrow: null,
child: Text( child: Text(
asset.name, asset.name,
style: TextStyle( style: TextStyle(
@ -103,11 +104,14 @@ class ReleaseItem extends StatelessWidget {
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
onClick: () {
context.pushUrl(asset.downloadUrl);
},
), ),
], ],
) ),
], ),
), ],
) )
], ],
); );

View File

@ -101,7 +101,7 @@ flutter:
# The following line ensures that the Material Icons font is # The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in # included with your application, so that you can use the icons in
# the material Icons class. # the material Icons class.
uses-material-design: true # uses-material-design: true
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
# assets: # assets: