aboutsummaryrefslogtreecommitdiff
path: root/lib/components/AppContextMenu.dart
blob: 72d67aa5049a8567b72f5a28d5dead0762ca5a38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import 'package:flutter/material.dart';
import 'package:device_apps/device_apps.dart';
import 'package:android_intent/android_intent.dart';
import 'package:android_intent/flag.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../data/favorites.dart';

class Option extends StatelessWidget {
  void Function() onTap;
  Widget icon;
  Widget child;

  Option({ this.child, this.icon, this.onTap }): super();

  @override
  build(BuildContext ctx) {
    return Column(
      children: [
        ListTile(
            contentPadding: const EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
            title: Row(children: [
              Container(width: 36.0, padding: EdgeInsets.only(right: 16.0), child: icon),
              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(
                icon: Icon(Icons.star, size: 22.0, color: theme.primaryColor),
                child: Text(isFavorite ? 'Remove from favorites' : 'Add to favorites'),
                onTap: () async {
                  await isFavorite ? removeFromFavorites(app) : addToFavorites(app);
                },
            ),
            Option(
                child: Text('App Settings'),
                icon: Icon(Icons.settings, size: 22.0, color: theme.primaryColor),
                onTap: () async {
                  await AndroidIntent(
                      action: 'action_application_details_settings',
                      data: 'package:${app.packageName}',
                  ).launch();
                },
            ),
            Option(
                child: Text('Uninstall'),
                icon: Icon(Icons.delete_forever, size: 22.0, color: theme.primaryColor),
                onTap: () async {
                  await AndroidIntent(
                      action: 'android.intent.action.DELETE',
                      data: 'package:${app.packageName}',
                  ).launch();
                },
            ),
          ],
        ),
      ),
    );
  }
}