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,17 +192,15 @@ 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: [ children: [
for (var commit in commits) ...[ for (var commit in commits) ...[
LinkWidget( LinkWidget(
@ -219,8 +219,7 @@ class GePullScreen extends StatelessWidget {
color: AntTheme.of(context) color: AntTheme.of(context)
.colorPrimary, .colorPrimary,
fontSize: 17, fontSize: 17,
fontFamily: fontFamily: CommonStyle.monospace,
CommonStyle.monospace,
), ),
), ),
], ],
@ -230,7 +229,6 @@ class GePullScreen extends StatelessWidget {
] ]
], ],
), ),
),
], ],
), ),
), ),

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,10 +26,14 @@ 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
},
panels: [
AntCollapsePanel(
key: '',
title: Text( title: Text(
filename!, filename!,
style: TextStyle( style: TextStyle(
@ -38,8 +42,7 @@ class FilesItem extends StatelessWidget {
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
), ),
), ),
children: <Widget>[ child: SingleChildScrollView(
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,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
children: <Widget>[
AntList(
children: [
if (releaseAssets != null)
for (var asset in releaseAssets!.nodes!)
AntListItem(
extra: IconButton(
onPressed: () {
context.pushUrl(asset.downloadUrl);
}, },
icon: const Icon(Ionicons.download_outline), panels: [
), AntCollapsePanel(
arrow: null, key: '',
title:
Text('Assets (${widget.releaseAssets?.nodes?.length ?? 0})'),
child: AntList(
children: [
if (widget.releaseAssets != null)
for (var asset in widget.releaseAssets!.nodes!)
AntListItem(
arrow: const Icon(Ionicons.download_outline),
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: