mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-04-28 10:28:58 -05:00
refactor: use list
This commit is contained in:
@@ -3,7 +3,6 @@ import 'package:file_icon/file_icon.dart';
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/table_view.dart';
|
||||
|
||||
Widget _buildIcon(String type, String name) {
|
||||
switch (type) {
|
||||
@@ -22,32 +21,35 @@ Widget _buildIcon(String type, String name) {
|
||||
}
|
||||
}
|
||||
|
||||
TableViewItem createObjectTreeItem({
|
||||
AntListItem createObjectTreeItem({
|
||||
required String name,
|
||||
required String type,
|
||||
required String url,
|
||||
String? downloadUrl,
|
||||
int? size,
|
||||
}) {
|
||||
return TableViewItem(
|
||||
return AntListItem(
|
||||
prefix: _buildIcon(type, name),
|
||||
child: Text(name),
|
||||
extra: size == null ? null : Text(filesize(size)),
|
||||
url: [
|
||||
// Let system browser handle these files
|
||||
//
|
||||
// TODO:
|
||||
// Unhandled Exception: PlatformException(Error, Error while launching
|
||||
// https://github.com/flutter/flutter/issues/49162
|
||||
onClick: () async {
|
||||
final finalUrl = [
|
||||
// Let system browser handle these files
|
||||
//
|
||||
// TODO:
|
||||
// Unhandled Exception: PlatformException(Error, Error while launching
|
||||
// https://github.com/flutter/flutter/issues/49162
|
||||
|
||||
// Docs
|
||||
'pdf', 'docx', 'doc', 'pptx', 'ppt', 'xlsx', 'xls',
|
||||
// Fonts
|
||||
'ttf', 'otf', 'eot', 'woff', 'woff2',
|
||||
'svg',
|
||||
].contains(name.ext)
|
||||
? downloadUrl
|
||||
: url,
|
||||
hideRightChevron: size != null,
|
||||
// Docs
|
||||
'pdf', 'docx', 'doc', 'pptx', 'ppt', 'xlsx', 'xls',
|
||||
// Fonts
|
||||
'ttf', 'otf', 'eot', 'woff', 'woff2',
|
||||
'svg',
|
||||
].contains(name.ext)
|
||||
? downloadUrl
|
||||
: url;
|
||||
await launchStringUrl(finalUrl);
|
||||
},
|
||||
arrow: size == null ? const Icon(AntIcons.rightOutline) : null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:antd_mobile/antd_mobile.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_gen/gen_l10n/S.dart';
|
||||
import 'package:git_touch/graphql/__generated__/github.data.gql.dart';
|
||||
@@ -5,7 +6,6 @@ import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/avatar.dart';
|
||||
import 'package:git_touch/widgets/markdown_view.dart';
|
||||
import 'package:git_touch/widgets/table_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
@@ -87,11 +87,11 @@ class ReleaseItem extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
children: <Widget>[
|
||||
TableView(
|
||||
AntList(
|
||||
items: [
|
||||
if (releaseAssets != null)
|
||||
for (var asset in releaseAssets!.nodes!)
|
||||
TableViewItem(
|
||||
AntListItem(
|
||||
child: Text(
|
||||
asset.name,
|
||||
style: TextStyle(
|
||||
@@ -105,7 +105,7 @@ class ReleaseItem extends StatelessWidget {
|
||||
theme.push(context, asset.downloadUrl);
|
||||
},
|
||||
icon: const Icon(Ionicons.download_outline)),
|
||||
hideRightChevron: true,
|
||||
arrow: null,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -24,30 +24,10 @@ class TableViewHeader extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class TableViewItem {
|
||||
final Widget child;
|
||||
final IconData? prefixIconData;
|
||||
final Widget? prefix;
|
||||
final Widget? extra;
|
||||
final void Function()? onClick;
|
||||
final String? url;
|
||||
final bool hideRightChevron;
|
||||
|
||||
const TableViewItem({
|
||||
required this.child,
|
||||
this.prefixIconData,
|
||||
this.prefix,
|
||||
this.extra,
|
||||
this.onClick,
|
||||
this.url,
|
||||
this.hideRightChevron = false,
|
||||
}) : assert(prefixIconData == null || prefix == null);
|
||||
}
|
||||
|
||||
class TableViewItemWidget extends StatelessWidget {
|
||||
const TableViewItemWidget(this.item, {super.key});
|
||||
|
||||
final TableViewItem item;
|
||||
final AntListItem item;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -55,7 +35,6 @@ class TableViewItemWidget extends StatelessWidget {
|
||||
|
||||
return LinkWidget(
|
||||
onTap: item.onClick,
|
||||
url: item.url,
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(fontSize: 17, color: theme.palette.text),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -64,16 +43,8 @@ class TableViewItemWidget extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: (item.prefix == null && item.prefixIconData == null)
|
||||
? 12
|
||||
: 44,
|
||||
child: Center(
|
||||
child: item.prefix ??
|
||||
Icon(
|
||||
item.prefixIconData,
|
||||
color: theme.palette.primary,
|
||||
size: 20,
|
||||
)),
|
||||
width: (item.prefix == null) ? 12 : 44,
|
||||
child: Center(child: item.prefix),
|
||||
),
|
||||
Expanded(child: item.child),
|
||||
if (item.extra != null) ...[
|
||||
@@ -86,8 +57,7 @@ class TableViewItemWidget extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: 6)
|
||||
],
|
||||
if ((item.onClick != null || item.url != null) &&
|
||||
!item.hideRightChevron)
|
||||
if (item.onClick != null)
|
||||
Icon(Ionicons.chevron_forward,
|
||||
size: 20, color: theme.palette.tertiaryText)
|
||||
else
|
||||
@@ -100,41 +70,3 @@ class TableViewItemWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TableView extends StatelessWidget {
|
||||
final Widget? header;
|
||||
final Iterable<TableViewItem> items;
|
||||
|
||||
const TableView({
|
||||
super.key,
|
||||
this.header,
|
||||
required this.items,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
|
||||
return AntList(
|
||||
header: header,
|
||||
items: [
|
||||
for (final item in items)
|
||||
AntListItem(
|
||||
child: item.child,
|
||||
prefix: item.prefix ??
|
||||
(item.prefixIconData == null
|
||||
? null
|
||||
: Icon(item.prefixIconData)),
|
||||
extra: item.extra,
|
||||
onClick: item.onClick != null
|
||||
? item.onClick!
|
||||
: item.url != null
|
||||
? () {
|
||||
theme.push(context, item.url!);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user