aboutsummaryrefslogtreecommitdiff
path: root/lib/pages/Apps.dart
blob: d267f10f3a2d7e2635bef8c0bed3ab6f86d2e50e (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
import 'package:flutter/material.dart';
import 'package:device_apps/device_apps.dart';

import '../components/FixedContainer.dart';
import '../components/SearchableAppList.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 AppsView extends StatelessWidget {
  Future<List<Application>> appListF = DeviceApps.getInstalledApplications(
      includeSystemApps: false,
      onlyAppsWithLaunchIntent: true,
  );

  void openApp(Application app) {
    DeviceApps.openApp(app.packageName);
  }

  void openOptionsMenu(BuildContext ctx, Application app) {
    showDialog(context: ctx, builder: (BuildContext ctx) => buildOptionsMenu(ctx, app));
  }

  Widget buildOptionsMenu(BuildContext ctx, Application app) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20.0),
        ),
        height: 300.0,
        width: 300.0,
        child: ListView(
          children: [
            Option(child: Text('Cool'), onTap: () { debugPrint('Cool'); }),
            Option(child: Text('Wow'),  onTap: () { debugPrint('Wow'); }),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext ctx) {
    return FixedContainer(
        padding: const EdgeInsets.symmetric(vertical: 36.0, horizontal: 16.0),
        child: SearchableAppList(
            appListF: appListF,
            openApp: openApp,
            openOptionsMenu: (app) => openOptionsMenu(ctx, app),
        ),
    );
  }
}