2019-02-20 09:31:22 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-10-07 18:55:47 +02:00
|
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-09-30 09:46:06 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2022-06-26 09:18:13 +02:00
|
|
|
import 'package:share_plus/share_plus.dart';
|
2019-02-20 09:31:22 +01:00
|
|
|
|
2019-09-30 09:46:06 +02:00
|
|
|
class ActionItem {
|
2019-09-30 10:28:55 +02:00
|
|
|
ActionItem({
|
2021-05-16 09:16:35 +02:00
|
|
|
required this.text,
|
2020-01-01 13:59:20 +01:00
|
|
|
this.onTap,
|
2022-09-17 15:57:43 +02:00
|
|
|
this.danger = false,
|
2019-09-30 10:28:55 +02:00
|
|
|
});
|
2022-09-21 18:28:21 +02:00
|
|
|
String? text;
|
|
|
|
bool danger;
|
|
|
|
void Function(BuildContext context)? onTap;
|
2019-02-20 09:31:22 +01:00
|
|
|
|
2021-05-16 09:16:35 +02:00
|
|
|
static List<ActionItem> getUrlActions(String? url) {
|
2020-01-27 06:41:17 +01:00
|
|
|
return [
|
|
|
|
ActionItem(
|
|
|
|
text: 'Share',
|
|
|
|
onTap: (_) {
|
2021-05-16 09:16:35 +02:00
|
|
|
Share.share(url!);
|
2020-01-27 06:41:17 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
ActionItem(
|
|
|
|
text: 'Open in Browser',
|
|
|
|
onTap: (_) {
|
2022-06-26 08:23:50 +02:00
|
|
|
launchStringUrl(url);
|
2020-01-27 06:41:17 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2019-02-20 09:31:22 +01:00
|
|
|
}
|
|
|
|
|
2022-09-24 07:22:07 +02:00
|
|
|
class ActionButton extends StatelessWidget {
|
2022-09-06 18:28:12 +02:00
|
|
|
const ActionButton({
|
2021-05-16 09:16:35 +02:00
|
|
|
required this.title,
|
|
|
|
required this.items,
|
2021-02-14 15:17:22 +01:00
|
|
|
this.iconData = Ionicons.ellipsis_horizontal,
|
2019-10-02 08:58:11 +02:00
|
|
|
this.selected,
|
2019-02-20 09:31:22 +01:00
|
|
|
});
|
2022-09-24 07:22:07 +02:00
|
|
|
|
2022-09-21 18:28:21 +02:00
|
|
|
final String title;
|
|
|
|
final List<ActionItem> items;
|
|
|
|
final IconData iconData;
|
|
|
|
final int? selected;
|
2022-09-24 07:22:07 +02:00
|
|
|
// TODO: selected, font bold
|
2019-02-20 09:31:22 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-01-01 13:59:20 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2022-09-17 14:35:45 +02:00
|
|
|
return CupertinoButton(
|
|
|
|
minSize: 0,
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
onPressed: () async {
|
2022-09-17 15:57:43 +02:00
|
|
|
await theme.showActions(context, items);
|
2022-09-17 14:35:45 +02:00
|
|
|
},
|
|
|
|
child: Icon(iconData, size: 22),
|
|
|
|
);
|
2019-02-20 09:31:22 +01:00
|
|
|
}
|
|
|
|
}
|