~cytrogen/fluent-reader-mobile

ref: 64c6aee08a7eb702d04aa60cec7131eda0e35820 fluent-reader-mobile/lib/components/my_list_tile.dart -rw-r--r-- 2.8 KiB
64c6aee0 — Bruce Liu add german language support 4 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import 'package:fluent_reader_lite/utils/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyListTile extends StatefulWidget {
  final Widget leading;
  final Widget title;
  final Widget trailing;
  final bool trailingChevron;
  final bool withDivider;
  final Function onTap;
  final CupertinoDynamicColor background;

  MyListTile({
    this.leading,
    @required this.title,
    this.trailing,
    this.trailingChevron : true,
    this.withDivider : true,
    this.onTap,
    this.background : MyColors.tileBackground,
    Key key,
  }) : super(key: key);

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

class _MyListTileState extends State<MyListTile> {
  bool pressed = false;

  void _onTap() {
    if (widget.onTap != null) widget.onTap();
  }

  @override
  Widget build(BuildContext context) {
    final _titleStyle = TextStyle(
      fontSize: 16,
      color: CupertinoColors.label.resolveFrom(context),
    );
    final leftPart = Flexible(child: Row(
      children: [
        if (widget.leading != null) Container(
          padding: EdgeInsets.only(right: 16),
          width: 40,
          height: 24,
          child: widget.leading,
        ),
        DefaultTextStyle(
          child: widget.title,
          style: _titleStyle,
        ),
      ],
    ));
    final _labelStyle = TextStyle(
      fontSize: 16,
      color: CupertinoColors.secondaryLabel.resolveFrom(context),
    );
    final rightPart = Row(
      children: [
        if (widget.trailing != null) DefaultTextStyle(
          child: widget.trailing,
          style: _labelStyle,
        ),
        if (widget.trailingChevron) Icon(
          CupertinoIcons.chevron_forward,
          color: CupertinoColors.tertiaryLabel.resolveFrom(context),
        ),
      ],
    );
    return GestureDetector(
      onTapDown: (_) { setState(() { pressed = true; }); },
      onTapUp: (_) { setState(() { pressed = false; }); },
      onTapCancel: () { setState(() { pressed = false; }); },
      onTap: _onTap,
      child: Column(children: [
        Container(
          color: (pressed && widget.onTap != null)
            ? CupertinoColors.systemGrey4.resolveFrom(context) 
            : widget.background.resolveFrom(context),
          padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
          constraints: BoxConstraints(minHeight: 48),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              leftPart,
              rightPart,
            ],
          ),
        ),
        if (widget.withDivider) Padding(
          padding: EdgeInsets.only(left: widget.leading == null ? 16 : 50),
          child: Divider(color: CupertinoColors.systemGrey4.resolveFrom(context), height: 0),
        ),
      ],),
    );
  }
}