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

import 'AppList.dart';

class _SearchableAppListState extends State<SearchableAppList> {
  String _searchTerm = '';

  void onInput(String str) {
    setState(() { _searchTerm = str; });
  }

  int _appSorter(Application a, Application b) {
    return a.appName.compareTo(b.appName);
  }

  @override
  Widget build(BuildContext ctx) {
    return Column(
        children: [
          Container(
            height: 100,
            child: TextField(
                decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: 'Enter a search term',
                ),
            ),
          ),
          Expanded(child: FutureBuilder(
            future: widget.appListF,
            builder: (ctx, AsyncSnapshot<List<Application>> snap) {
              if (!snap.hasData) {
                return Text('Loading...');
              }

              snap.data.sort(_appSorter);
              return AppList(
                  appList: snap.data,
                  openApp: widget.openApp,
                  openOptionsMenu: widget.openOptionsMenu,
              );
            }
          )),
        ],
    );
  }
}

class SearchableAppList extends StatefulWidget {
  Future<List<Application>> appListF;
  void Function(Application) openApp;
  void Function(Application) openOptionsMenu;
  
  SearchableAppList({ this.appListF, this.openApp, this.openOptionsMenu }): super();

  @override
  _SearchableAppListState createState() => _SearchableAppListState();
}