mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 11:48:02 +01:00
refactor: link widget
This commit is contained in:
parent
91d6a4b2a3
commit
bc068c20ee
@ -52,8 +52,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAddItem(
|
||||
{String text, Function onTap, WidgetBuilder screenBuilder}) {
|
||||
Widget _buildAddItem({String text, Function onTap}) {
|
||||
return Link(
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 20),
|
||||
@ -69,7 +68,6 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
),
|
||||
),
|
||||
onTap: onTap,
|
||||
screenBuilder: screenBuilder,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -9,33 +9,26 @@ class Link extends StatelessWidget {
|
||||
final String url;
|
||||
final WidgetBuilder screenBuilder;
|
||||
final Function onTap;
|
||||
final Color bgColor;
|
||||
final bool material;
|
||||
final bool fullscreenDialog;
|
||||
final Icon iconButton;
|
||||
|
||||
Link({
|
||||
this.child,
|
||||
this.url,
|
||||
this.screenBuilder,
|
||||
this.onTap,
|
||||
this.bgColor,
|
||||
this.material = true,
|
||||
this.fullscreenDialog = false,
|
||||
this.iconButton,
|
||||
}) : assert(child != null || iconButton != null),
|
||||
assert(screenBuilder == null || url == null);
|
||||
}) : assert(screenBuilder == null || url == null);
|
||||
|
||||
void _onTap(BuildContext context, int theme) {
|
||||
void _onTap(BuildContext context) {
|
||||
if (onTap != null) {
|
||||
onTap();
|
||||
return onTap();
|
||||
}
|
||||
|
||||
if (screenBuilder != null) {
|
||||
Provider.of<ThemeModel>(context).pushRoute(context, screenBuilder,
|
||||
return Provider.of<ThemeModel>(context).pushRoute(context, screenBuilder,
|
||||
fullscreenDialog: fullscreenDialog);
|
||||
}
|
||||
|
||||
if (url != null) {
|
||||
launch(url);
|
||||
}
|
||||
@ -43,30 +36,21 @@ class Link extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var theme = Provider.of<ThemeModel>(context).theme;
|
||||
|
||||
if (iconButton != null) {
|
||||
return IconButton(
|
||||
icon: iconButton,
|
||||
onPressed: () => _onTap(context, theme),
|
||||
);
|
||||
}
|
||||
|
||||
if (!material) {
|
||||
return GestureDetector(
|
||||
child: child,
|
||||
onTap: () => _onTap(context, theme),
|
||||
onTap: () => _onTap(context),
|
||||
);
|
||||
}
|
||||
|
||||
return Material(
|
||||
child: Ink(
|
||||
color: bgColor ?? Colors.white,
|
||||
color: Colors.white,
|
||||
child: InkWell(
|
||||
child: child,
|
||||
// splashColor:
|
||||
// theme == AppThemeType.cupertino ? Colors.transparent : null,
|
||||
onTap: () => _onTap(context, theme),
|
||||
onTap: () => _onTap(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/models/notification.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:primer/primer.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../utils/utils.dart';
|
||||
@ -96,38 +97,34 @@ class _NotificationItemState extends State<NotificationItem> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
WidgetBuilder screenBuilder;
|
||||
Function onTap;
|
||||
|
||||
switch (payload.type) {
|
||||
case 'Issue':
|
||||
case 'PullRequest':
|
||||
screenBuilder = (_) => IssueScreen(
|
||||
number: payload.number,
|
||||
owner: payload.owner,
|
||||
name: payload.name,
|
||||
isPullRequest: payload.type == 'PullRequest',
|
||||
);
|
||||
break;
|
||||
case 'Release':
|
||||
onTap = () {
|
||||
launch(
|
||||
'https://github.com/${payload.owner}/${payload.name}/releases/tag/${payload.title}');
|
||||
};
|
||||
break;
|
||||
case 'Commit':
|
||||
// TODO:
|
||||
// onTap = () {
|
||||
// launch('urlString');
|
||||
// };
|
||||
break;
|
||||
}
|
||||
|
||||
return Link(
|
||||
screenBuilder: screenBuilder,
|
||||
onTap: () {
|
||||
_markAsRead();
|
||||
if (onTap != null) onTap();
|
||||
|
||||
switch (payload.type) {
|
||||
case 'Issue':
|
||||
case 'PullRequest':
|
||||
Provider.of<ThemeModel>(context).pushRoute(
|
||||
context,
|
||||
(_) => IssueScreen(
|
||||
number: payload.number,
|
||||
owner: payload.owner,
|
||||
name: payload.name,
|
||||
isPullRequest: payload.type == 'PullRequest',
|
||||
));
|
||||
|
||||
break;
|
||||
case 'Release':
|
||||
launch(
|
||||
'https://github.com/${payload.owner}/${payload.name}/releases/tag/${payload.title}');
|
||||
break;
|
||||
case 'Commit':
|
||||
// TODO:
|
||||
// onTap = () {
|
||||
// launch('urlString');
|
||||
// };
|
||||
break;
|
||||
}
|
||||
},
|
||||
child: Opacity(
|
||||
opacity: payload.unread ? 1 : 0.5,
|
||||
|
@ -103,7 +103,7 @@ class TableView extends StatelessWidget {
|
||||
);
|
||||
|
||||
if (item.onTap == null && item.screenBuilder == null && item.url == null) {
|
||||
return Ink(color: PrimerColors.white, child: widget);
|
||||
return widget;
|
||||
}
|
||||
return Link(
|
||||
onTap: item.onTap,
|
||||
|
Loading…
x
Reference in New Issue
Block a user