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

View File

@ -9,8 +9,6 @@ import 'package:tuple/tuple.dart';
import 'package:universal_io/io.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'
show Octicons, Ionicons;

View File

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

View File

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