1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-18 19:22:54 +01:00
git-touch-android-ios-app/lib/widgets/action.dart
2019-09-29 13:47:18 +08:00

69 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:git_touch/widgets/action_entry.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/models/theme.dart';
class MyAction {
String text;
Function onPress;
MyAction({@required this.text, @required this.onPress});
}
class ActionButton extends StatelessWidget {
final String title;
final List<MyAction> actions;
final IconData iconData;
ActionButton({
@required this.title,
@required this.actions,
this.iconData = Icons.more_vert,
});
void _onSelected(int value) {
if (value != null) {
actions[value].onPress();
}
}
@override
Widget build(BuildContext context) {
switch (Provider.of<ThemeModel>(context).theme) {
case AppThemeType.cupertino:
default:
return ActionEntry(
iconData: iconData,
onTap: () async {
int value = await showCupertinoModalPopup<int>(
context: context,
builder: (BuildContext context) {
return CupertinoActionSheet(
title: Text(title),
actions: actions.asMap().entries.map((entry) {
return CupertinoActionSheetAction(
child: Text(entry.value.text),
onPressed: () {
Navigator.pop(context, entry.key);
},
);
}).toList(),
cancelButton: CupertinoActionSheetAction(
child: const Text('Cancel'),
isDefaultAction: true,
onPressed: () {
Navigator.pop(context);
},
),
);
},
);
_onSelected(value);
},
);
}
}
}