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

class AppList extends StatelessWidget {
  final List<Application> appList;
  final void Function(Application) openApp;
  final void Function(Application) openOptionsMenu;
  final bool allowReorder;
  
  AppList({ this.appList, this.openApp, this.openOptionsMenu, this.allowReorder = false }): super();

  onReorder(int a, int b) {
    // 
  }

  Widget buildItem(Application app) {
    return Container(
      key: Key(app.packageName),
      child: ListTile(
        contentPadding: const EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
        dense: true,
        title: Text('${app.appName}', style: const TextStyle(fontSize: 16)),
        onTap: () => openApp(app),
        onLongPress: () => !this.allowReorder ? openOptionsMenu(app) : null,
      ),
    );
  }

  @override
  Widget build(BuildContext ctx) {
    if (this.allowReorder) {
      return ReorderableListView(
        key: Key("reorderlist"),
        onReorder: this.onReorder,
        children: appList.map(this.buildItem).toList(),
      );
    }
    return ListView.builder(
      itemCount: appList.length,
      itemBuilder: (ctx, index) {
        return this.buildItem(appList[index]);
      },
    );
  }
}