git-touch-android-ios-app/lib/widgets/link.dart

59 lines
1.4 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;
final bool material;
final bool fullscreenDialog;
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.material = true,
this.fullscreenDialog = false,
2019-09-24 15:04:30 +02:00
}) : assert(screenBuilder == null || url == null);
2019-01-31 07:37:25 +01:00
2019-09-24 15:04:30 +02:00
void _onTap(BuildContext context) {
if (onTap != null) {
2019-09-24 15:04:30 +02:00
return onTap();
}
if (screenBuilder != null) {
2019-09-24 15:04:30 +02:00
return Provider.of<ThemeModel>(context).pushRoute(context, screenBuilder,
fullscreenDialog: fullscreenDialog);
}
if (url != null) {
launch(url);
}
}
2019-01-31 07:37:25 +01:00
@override
Widget build(BuildContext context) {
if (!material) {
return GestureDetector(
child: child,
2019-09-24 15:04:30 +02:00
onTap: () => _onTap(context),
);
}
2019-01-31 07:37:25 +01:00
return Material(
child: Ink(
2019-09-24 15:04:30 +02:00
color: Colors.white,
2019-01-31 07:37:25 +01:00
child: InkWell(
child: child,
// splashColor:
// theme == AppThemeType.cupertino ? Colors.transparent : null,
2019-09-24 15:04:30 +02:00
onTap: () => _onTap(context),
2019-01-31 07:37:25 +01:00
),
),
);
}
}