1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 18:59:23 +01:00
git-touch-android-ios-app/lib/widgets/link.dart

77 lines
1.7 KiB
Dart
Raw Normal View History

2019-01-31 07:37:25 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:git_touch/models/theme.dart';
2019-01-31 07:37:25 +01:00
class Link extends StatelessWidget {
final Widget child;
final String url;
final WidgetBuilder screenBuilder;
final Function onTap;
2019-02-06 06:06:11 +01:00
final Color bgColor;
final bool material;
final bool fullscreenDialog;
2019-02-08 16:20:28 +01:00
final Icon iconButton;
2019-01-31 07:37:25 +01:00
Link({
2019-02-08 16:20:28 +01:00
this.child,
this.url,
this.screenBuilder,
this.onTap,
this.bgColor,
this.material = true,
this.fullscreenDialog = false,
2019-02-08 16:20:28 +01:00
this.iconButton,
}) : assert(child != null || iconButton != null),
assert(screenBuilder == null || url == null);
2019-01-31 07:37:25 +01:00
void _onTap(BuildContext context, int theme) {
if (onTap != null) {
onTap();
}
if (screenBuilder != null) {
Provider.of<ThemeModel>(context).pushRoute(
context: context,
builder: screenBuilder,
fullscreenDialog: fullscreenDialog);
}
if (url != null) {
launch(url);
}
}
2019-01-31 07:37:25 +01:00
@override
Widget build(BuildContext context) {
var theme = Provider.of<ThemeModel>(context).theme;
2019-02-08 16:20:28 +01:00
if (iconButton != null) {
return IconButton(
icon: iconButton,
onPressed: () => _onTap(context, theme),
);
}
if (!material) {
return GestureDetector(
child: child,
onTap: () => _onTap(context, theme),
);
}
2019-01-31 07:37:25 +01:00
return Material(
child: Ink(
2019-02-06 06:06:11 +01:00
color: bgColor ?? Colors.white,
2019-01-31 07:37:25 +01:00
child: InkWell(
child: child,
2019-09-15 11:36:09 +02:00
splashColor:
theme == AppThemeMap.cupertino ? Colors.transparent : null,
onTap: () => _onTap(context, theme),
2019-01-31 07:37:25 +01:00
),
),
);
}
}