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-09-02 15:52:32 +02:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
|
2019-12-31 12:52:00 +01:00
|
|
|
// TODO:
|
|
|
|
class CupertinoLink extends StatefulWidget {
|
|
|
|
final Widget child;
|
|
|
|
final Function onTap;
|
|
|
|
|
|
|
|
CupertinoLink({this.child, this.onTap});
|
|
|
|
|
|
|
|
@override
|
|
|
|
_CupertinoLinkState createState() => _CupertinoLinkState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CupertinoLinkState extends State<CupertinoLink> {
|
|
|
|
Color _color;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
color: _color,
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: widget.onTap,
|
|
|
|
onTapDown: (_) {
|
|
|
|
print('down');
|
|
|
|
setState(() {
|
|
|
|
_color = Colors.black12;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onTapUp: (_) {
|
|
|
|
print('up');
|
|
|
|
setState(() {
|
|
|
|
_color = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onTapCancel: () {
|
|
|
|
print('cacnel');
|
|
|
|
setState(() {
|
|
|
|
_color = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: widget.child,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 07:37:25 +01:00
|
|
|
class Link extends StatelessWidget {
|
|
|
|
final Widget child;
|
2019-02-10 07:26:51 +01:00
|
|
|
final String url;
|
2019-02-21 11:43:41 +01:00
|
|
|
final Function onTap;
|
2020-02-01 11:30:32 +01:00
|
|
|
final Function onLongPress;
|
2019-01-31 07:37:25 +01:00
|
|
|
|
2019-02-07 12:17:29 +01:00
|
|
|
Link({
|
2020-02-01 11:30:32 +01:00
|
|
|
@required this.child,
|
2019-02-10 07:26:51 +01:00
|
|
|
this.url,
|
2019-02-21 11:43:41 +01:00
|
|
|
this.onTap,
|
2020-02-01 11:30:32 +01:00
|
|
|
this.onLongPress,
|
2019-12-13 04:02:05 +01:00
|
|
|
});
|
2019-01-31 07:37:25 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-12-26 07:10:52 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2019-11-05 14:22:41 +01:00
|
|
|
|
2019-12-31 12:52:00 +01:00
|
|
|
switch (theme.theme) {
|
|
|
|
case AppThemeType.cupertino:
|
2020-02-01 11:30:32 +01:00
|
|
|
Widget w = CupertinoButton(
|
2020-01-04 15:46:33 +01:00
|
|
|
minSize: 0,
|
2019-12-31 12:52:00 +01:00
|
|
|
child: child,
|
2020-01-04 15:46:33 +01:00
|
|
|
padding: EdgeInsets.zero,
|
2019-12-31 12:52:00 +01:00
|
|
|
onPressed: () async {
|
|
|
|
if (onTap != null) onTap();
|
2020-01-01 13:05:32 +01:00
|
|
|
if (url != null) theme.push(context, url);
|
2019-12-31 12:52:00 +01:00
|
|
|
},
|
|
|
|
);
|
2020-02-01 11:30:32 +01:00
|
|
|
if (onLongPress != null) {
|
|
|
|
w = GestureDetector(onLongPress: onLongPress, child: w);
|
|
|
|
}
|
|
|
|
return w;
|
2019-12-31 12:52:00 +01:00
|
|
|
default:
|
|
|
|
return InkWell(
|
2019-01-31 07:37:25 +01:00
|
|
|
child: child,
|
2019-12-26 07:10:52 +01:00
|
|
|
onTap: () async {
|
2019-12-27 03:24:15 +01:00
|
|
|
if (onTap != null) onTap();
|
2020-01-01 13:05:32 +01:00
|
|
|
if (url != null) theme.push(context, url);
|
2019-12-26 07:10:52 +01:00
|
|
|
},
|
2020-02-01 11:30:32 +01:00
|
|
|
onLongPress: onLongPress,
|
2019-12-31 12:52:00 +01:00
|
|
|
);
|
|
|
|
}
|
2019-01-31 07:37:25 +01:00
|
|
|
}
|
|
|
|
}
|