2019-02-07 12:17:29 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2022-09-13 19:19:52 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
|
2019-12-31 12:52:00 +01:00
|
|
|
// TODO:
|
|
|
|
class CupertinoLink extends StatefulWidget {
|
2022-09-06 18:28:12 +02:00
|
|
|
const CupertinoLink({this.child, this.onTap});
|
2022-09-21 18:28:21 +02:00
|
|
|
final Widget? child;
|
|
|
|
final Function? onTap;
|
2019-12-31 12:52:00 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
_CupertinoLinkState createState() => _CupertinoLinkState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CupertinoLinkState extends State<CupertinoLink> {
|
2021-05-16 09:16:35 +02:00
|
|
|
Color? _color;
|
2019-12-31 12:52:00 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
color: _color,
|
|
|
|
child: GestureDetector(
|
2021-05-16 09:16:35 +02:00
|
|
|
onTap: widget.onTap as void Function()?,
|
2019-12-31 12:52:00 +01:00
|
|
|
onTapDown: (_) {
|
|
|
|
print('down');
|
|
|
|
setState(() {
|
|
|
|
_color = Colors.black12;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onTapUp: (_) {
|
|
|
|
print('up');
|
|
|
|
setState(() {
|
|
|
|
_color = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onTapCancel: () {
|
|
|
|
print('cacnel');
|
|
|
|
setState(() {
|
|
|
|
_color = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: widget.child,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-16 09:16:35 +02:00
|
|
|
class LinkWidget extends StatelessWidget {
|
2022-09-06 18:28:12 +02:00
|
|
|
const LinkWidget({
|
2021-05-16 09:16:35 +02: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
|
|
|
});
|
2022-09-21 18:28:21 +02:00
|
|
|
final Widget child;
|
|
|
|
final String? url;
|
|
|
|
final Function? onTap;
|
|
|
|
final Function? onLongPress;
|
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
|
|
|
|
2022-09-17 14:35:45 +02:00
|
|
|
Widget w = CupertinoButton(
|
|
|
|
minSize: 0,
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
onPressed: () async {
|
|
|
|
if (onTap != null) onTap!();
|
2022-09-22 19:50:45 +02:00
|
|
|
if (url != null) context.pushUrl(url!);
|
2022-09-17 14:35:45 +02:00
|
|
|
},
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
if (onLongPress != null) {
|
|
|
|
w = GestureDetector(
|
|
|
|
onLongPress: onLongPress as void Function()?, child: w);
|
2019-12-31 12:52:00 +01:00
|
|
|
}
|
2022-09-17 14:35:45 +02:00
|
|
|
return w;
|
2019-01-31 07:37:25 +01:00
|
|
|
}
|
|
|
|
}
|