2019-01-31 07:37:25 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-07 12:17:29 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
import '../providers/settings.dart';
|
|
|
|
|
|
|
|
class Link extends StatelessWidget {
|
|
|
|
final Widget child;
|
2019-02-07 12:17:29 +01:00
|
|
|
final WidgetBuilder screenBuilder;
|
|
|
|
final Function beforeRedirect;
|
2019-02-06 06:06:11 +01:00
|
|
|
final Color bgColor;
|
2019-02-08 12:34:07 +01:00
|
|
|
final bool material;
|
|
|
|
final bool fullscreenDialog;
|
2019-01-31 07:37:25 +01:00
|
|
|
|
2019-02-07 12:17:29 +01:00
|
|
|
Link({
|
|
|
|
@required this.child,
|
|
|
|
this.screenBuilder,
|
|
|
|
this.beforeRedirect,
|
|
|
|
this.bgColor,
|
2019-02-08 12:34:07 +01:00
|
|
|
this.material = true,
|
|
|
|
this.fullscreenDialog = false,
|
2019-02-07 12:17:29 +01:00
|
|
|
});
|
2019-01-31 07:37:25 +01:00
|
|
|
|
2019-02-08 12:34:07 +01:00
|
|
|
void _onTap(BuildContext context, int theme) {
|
|
|
|
if (beforeRedirect != null) {
|
|
|
|
beforeRedirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screenBuilder != null) {
|
|
|
|
switch (theme) {
|
|
|
|
case ThemeMap.cupertino:
|
|
|
|
Navigator.of(context).push(CupertinoPageRoute(
|
|
|
|
builder: screenBuilder,
|
|
|
|
fullscreenDialog: fullscreenDialog,
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: screenBuilder,
|
|
|
|
fullscreenDialog: fullscreenDialog,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 07:37:25 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-02-07 12:17:29 +01:00
|
|
|
var theme = SettingsProvider.of(context).theme;
|
2019-02-08 12:34:07 +01:00
|
|
|
|
|
|
|
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-02-07 12:17:29 +01:00
|
|
|
splashColor: theme == ThemeMap.cupertino ? Colors.transparent : null,
|
2019-02-08 12:34:07 +01:00
|
|
|
onTap: () => _onTap(context, theme),
|
2019-01-31 07:37:25 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|