diff options
Diffstat (limited to '')
| -rw-r--r-- | lib/components/AppContextMenu.dart | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/components/AppContextMenu.dart b/lib/components/AppContextMenu.dart new file mode 100644 index 0000000..4dcc93a --- /dev/null +++ b/lib/components/AppContextMenu.dart @@ -0,0 +1,71 @@ +import 'package:flutter/material.dart'; +import 'package:device_apps/device_apps.dart'; +import 'package:android_intent/android_intent.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../data/favorites.dart'; + +class Option extends StatelessWidget { + void Function() onTap; + Widget child; + + Option({ this.child, this.onTap }): super(); + + @override + build(BuildContext ctx) { + return Column( + children: [ + ListTile( + contentPadding: const EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0), + title: child, + onTap: () { + onTap(); + Navigator.pop(ctx); + }, + ), + Divider(height: 1.0), + ], + ); + } +} + +class AppContextMenu extends StatelessWidget { + final Application app; + final bool isFavorite; + + AppContextMenu({ this.app, this.isFavorite }): super(); + + @override + Widget build(BuildContext ctx) { + ThemeData theme = Theme.of(ctx); + + return Dialog( + child: Container( + decoration: BoxDecoration( + color: theme.backgroundColor, + ), + height: 170.0, + child: ListView( + children: [ + Option(child: Text(isFavorite ? 'Remove from favorites' : 'Add to favorites'), onTap: () async { + await isFavorite ? removeFromFavorites(app) : addToFavorites(app); + }), + Option(child: Text('App Settings'), onTap: () async { + await AndroidIntent( + action: 'action_application_details_settings', + data: 'package:${app.packageName}', + ).launch(); + }), + Option(child: Text('Uninstall'), onTap: () async { + // FIXME: Doesn't work + await AndroidIntent( + action: 'action_delete', + data: 'package:${app.packageName}', + ).launch(); + }), + ], + ), + ), + ); + } +} |
