dev
dart 108 lines 4.41 KB
Raw
1 import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
2 import 'package:flutter/material.dart';
3
4 class SettingsChoicesCell extends StatelessWidget {
5 const SettingsChoicesCell(this.choicesListItem,
6 {this.useGenericColor = true, this.padding, Key? key})
7 : super(key: key);
8
9 final ChoicesListItem<dynamic> choicesListItem;
10 final bool useGenericColor;
11 final EdgeInsets? padding;
12
13 @override
14 Widget build(BuildContext context) {
15 final items = choicesListItem.items;
16 final selectedIndex = items.indexOf(choicesListItem.selectedItem);
17 final itemCount = items.length;
18
19 return Container(
20 color: useGenericColor ? Theme.of(context).colorScheme.surface : null,
21 padding: padding ?? const EdgeInsets.only(left: 24, right: 24, top: 16, bottom: 16),
22 child: Column(
23 mainAxisSize: MainAxisSize.min,
24 crossAxisAlignment: CrossAxisAlignment.start,
25 children: [
26 if (choicesListItem.title.isNotEmpty) ...[
27 Row(
28 children: [
29 Text(
30 choicesListItem.title,
31 style: Theme.of(context).textTheme.bodyMedium,
32 ),
33 ],
34 ),
35 const SizedBox(height: 12),
36 ],
37 Center(
38 child: Container(
39 decoration: BoxDecoration(
40 borderRadius: BorderRadius.circular(12),
41 border: useGenericColor
42 ? null
43 : Border.all(
44 color: Theme.of(context).colorScheme.surfaceContainerHighest,
45 width: 1.5,
46 ),
47 color:
48 useGenericColor ? Theme.of(context).colorScheme.surfaceContainerHighest : null,
49 ),
50 child: LayoutBuilder(
51 builder: (context, constraints) {
52 final itemWidth = constraints.maxWidth / itemCount;
53 return Stack(
54 children: [
55 if (selectedIndex >= 0)
56 AnimatedPositioned(
57 duration: const Duration(milliseconds: 450),
58 curve: Curves.easeInOut,
59 left: selectedIndex * itemWidth,
60 top: 0,
61 bottom: 0,
62 width: itemWidth,
63 child: Container(
64 decoration: BoxDecoration(
65 borderRadius: BorderRadius.circular(12),
66 color: Theme.of(context).colorScheme.primary,
67 ),
68 ),
69 ),
70 Row(
71 children: items.map((dynamic e) {
72 final isSelected = choicesListItem.selectedItem == e;
73 return Expanded(
74 child: GestureDetector(
75 onTap: () => choicesListItem.onItemSelected.call(e),
76 child: Container(
77 padding: const EdgeInsets.symmetric(vertical: 8),
78 color: Colors.transparent,
79 child: Center(
80 child: AnimatedDefaultTextStyle(
81 duration: const Duration(milliseconds: 220),
82 curve: Curves.easeInOut,
83 style: Theme.of(context).textTheme.bodyMedium!.copyWith(
84 color: isSelected
85 ? Theme.of(context).colorScheme.onPrimary
86 : Theme.of(context).colorScheme.onSurfaceVariant,
87 fontWeight:
88 isSelected ? FontWeight.w600 : FontWeight.normal,
89 ),
90 child: Text(choicesListItem.displayItem.call(e)),
91 ),
92 ),
93 ),
94 ),
95 );
96 }).toList(),
97 ),
98 ],
99 );
100 },
101 ),
102 ),
103 ),
104 ],
105 ),
106 );
107 }
108 }