dev
dart 71 lines 2.16 KB
Raw
1 import 'package:cake_wallet/src/widgets/standard_list.dart';
2 import 'package:cake_wallet/src/widgets/standard_switch.dart';
3 import 'package:flutter/material.dart';
4
5 class SettingsSwitcherCell extends StandardListRow {
6 SettingsSwitcherCell({
7 required String title,
8 required this.value,
9 this.onValueChange,
10 Decoration? decoration,
11 this.leading,
12 void Function(BuildContext context)? onTap,
13 Key? key,
14 this.padding,
15 this.switchBackgroundColor,
16 this.height = 56,
17 }) : super(title: title, isSelected: false, decoration: decoration, onTap: onTap, key: key);
18
19 final bool value;
20 final Color? switchBackgroundColor;
21 final void Function(BuildContext context, bool value)? onValueChange;
22 final Widget? leading;
23 final EdgeInsets? padding;
24 final double? height;
25
26 @override
27 Widget buildTrailing(BuildContext context) => StandardSwitch(
28 value: value,
29 onTapped: () => onValueChange?.call(context, !value),
30 backgroundColor: switchBackgroundColor,
31 );
32
33 @override
34 Widget build(BuildContext context) {
35 final leading = buildLeading(context);
36 final trailing = buildTrailing(context);
37 return Container(
38 height: height,
39 padding: padding ?? EdgeInsets.only(left: 12, right: 12),
40 child: TextButton(
41 onPressed: () {
42 if (onTap != null) {
43 onTap!.call(context);
44 } else {
45 onValueChange?.call(context, !value);
46 }
47 },
48 style: ButtonStyle(
49 padding: WidgetStateProperty.all(padding ?? null),
50 //backgroundColor: MaterialStateProperty.all(Theme.of(context).colorScheme.surfaceContainer),
51 shape: WidgetStateProperty.all(
52 RoundedRectangleBorder(
53 borderRadius: BorderRadius.all(Radius.circular(10)),
54 ),
55 ),
56 ),
57 child: Row(
58 mainAxisAlignment: MainAxisAlignment.spaceBetween,
59 children: <Widget>[
60 if (leading != null) leading,
61 buildCenter(context, hasLeftOffset: leading != null),
62 trailing,
63 ],
64 ),
65 ),
66 );
67 }
68
69 @override
70 Widget? buildLeading(BuildContext context) => leading;
71 }