dev
dart 79 lines 2.54 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
3
4 class SeedPhraseGridWidget extends StatelessWidget {
5 const SeedPhraseGridWidget({
6 super.key,
7 required this.list,
8 });
9
10 final List<String> list;
11
12 @override
13 Widget build(BuildContext context) {
14 int minTiles = 1;
15 int maxTiles = 4;
16 double desiredTileWidth = 120;
17 double spacing = 4;
18 double padding = 4;
19 double screenWidth = MediaQuery.of(context).size.width;
20
21 int crossAxisCount =
22 ((screenWidth + spacing - (2 * padding)) / (desiredTileWidth + spacing)).floor();
23
24 if (crossAxisCount > maxTiles) crossAxisCount = maxTiles;
25 if (crossAxisCount < minTiles) crossAxisCount = minTiles;
26
27 return GridView.builder(
28 itemCount: list.length,
29 controller: ModalScrollController.of(context),
30 gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
31 crossAxisCount: crossAxisCount,
32 childAspectRatio: 2.6,
33 mainAxisSpacing: 8.0,
34 crossAxisSpacing: 8.0,
35 ),
36 itemBuilder: (context, index) {
37 final item = list[index];
38 final numberCount = index + 1;
39
40 return Container(
41 padding: const EdgeInsets.symmetric(horizontal: 8),
42 alignment: Alignment.center,
43 decoration: BoxDecoration(
44 borderRadius: BorderRadius.circular(8),
45 color: Theme.of(context).colorScheme.surfaceContainerHigh),
46 child: Row(
47 crossAxisAlignment: CrossAxisAlignment.center,
48 children: [
49 SizedBox(
50 child: Text(
51 numberCount.toString(),
52 textAlign: TextAlign.center,
53 style: Theme.of(context).textTheme.bodyLarge?.copyWith(
54 height: 1.9,
55 fontWeight: FontWeight.w700,
56 color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
57 ),
58 softWrap: true,
59 maxLines: null,
60 ),
61 ),
62 const SizedBox(width: 6),
63 Expanded(
64 child: Text(
65 '${item[0].toLowerCase()}${item.substring(1)}',
66 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
67 height: 1,
68 fontWeight: FontWeight.w700,
69 color: Theme.of(context).colorScheme.onSurface,
70 ),
71 ),
72 ),
73 ],
74 ),
75 );
76 },
77 );
78 }
79 }