~cytrogen/fluent-reader-mobile

ref: d61062f4139b621c3e58f6c69f815e46ba83ec65 fluent-reader-mobile/lib/components/list_tile_group.dart -rw-r--r-- 1.7 KiB
d61062f4 — Bruce Liu add unread sources only option 5 years ago
                                                                                
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:fluent_reader_lite/components/my_list_tile.dart';
import 'package:fluent_reader_lite/utils/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tuple/tuple.dart';

class ListTileGroup extends StatelessWidget {
  ListTileGroup(this.children, {this.title, Key key}) : super(key: key);

  ListTileGroup.fromOptions(
    List<Tuple2<String, dynamic>> options, 
    dynamic selected, 
    Function onSelected,
    {this.title, Key key}) :
    children = options.map((t) => MyListTile(
      title: Text(t.item1),
      trailing: t.item2 == selected
        ? Icon(Icons.done)
        : Icon(null),
      trailingChevron: false,
      onTap: () { onSelected(t.item2); },
      withDivider: t.item2 != options.last.item2,
    )),
    super(key: key);

  final Iterable<Widget> children;
  final String title;

  static const _titleStyle = TextStyle(
    fontSize: 12,
    color: CupertinoColors.systemGrey,
  );

  @override
  Widget build(BuildContext context) => Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      if (title != null) Padding(
        padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
        child: Text(title, style: _titleStyle),
      ),
      Container(
        color: MyColors.tileBackground.resolveFrom(context),
        child: Column(children: [
          Divider(
            color: CupertinoColors.systemGrey5.resolveFrom(context),
            height: 1,
            thickness: 1,
          ),
          ...children,
          Divider(
            color: CupertinoColors.systemGrey5.resolveFrom(context),
            height: 1,
            thickness: 1,
          ),
        ],
      ),
    ),
  ],);
}