diff options
Diffstat (limited to 'lib/components/AppList.dart')
| -rw-r--r-- | lib/components/AppList.dart | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/components/AppList.dart b/lib/components/AppList.dart index 5b54b04..d9fdd95 100644 --- a/lib/components/AppList.dart +++ b/lib/components/AppList.dart @@ -2,30 +2,43 @@ import 'package:flutter/material.dart'; import 'package:device_apps/device_apps.dart'; class AppList extends StatelessWidget { - List<Application> appList; - void Function(Application) openApp; - void Function(Application) openOptionsMenu; + final List<Application> appList; + final void Function(Application) openApp; + final void Function(Application) openOptionsMenu; + final bool allowReorder; - AppList({ this.appList, this.openApp, this.openOptionsMenu }): super(); + 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) { - Application app = appList[index]; - return Column( - children: [ - 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: () => openOptionsMenu(app), - ), - Divider(height: 1.0), - ], - ); + return this.buildItem(appList[index]); }, ); } |
