This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcard_picker.dart
120 lines (114 loc) · 4.29 KB
/
card_picker.dart
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import "package:aqua/src/common_widgets/playing_card.dart";
import "package:flutter/services.dart";
import "package:flutter/widgets.dart";
import "package:poker/poker.dart";
class CardPicker extends StatelessWidget {
CardPicker({
CardSet? unavailableCards,
void Function(Card)? onCardTap,
Key? key,
}) : unavailableCards = unavailableCards ?? CardSet.empty,
onCardTap = onCardTap ?? ((_) {}),
super(key: key);
final CardSet unavailableCards;
final void Function(Card) onCardTap;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: List.generate(
_cards.length * 2 - 1,
(i) => i % 2 == 0
? Row(
children: List.generate(
_cards[i ~/ 2].length * 2 - 1,
(j) => j % 2 == 0
? Expanded(
child:
unavailableCards.contains(_cards[i ~/ 2][j ~/ 2])
? Opacity(
opacity: 0.25,
child: PlayingCard(
card: _cards[i ~/ 2][j ~/ 2],
),
)
: GestureDetector(
onTap: () {
HapticFeedback.selectionClick();
onCardTap(_cards[i ~/ 2][j ~/ 2]);
},
child: PlayingCard(
card: _cards[i ~/ 2][j ~/ 2],
),
),
)
: SizedBox(width: 2),
),
)
: SizedBox(height: 2),
),
);
}
}
final _cards = [
[
Card(rank: Rank.ace, suit: Suit.spade),
Card(rank: Rank.king, suit: Suit.spade),
Card(rank: Rank.queen, suit: Suit.spade),
Card(rank: Rank.jack, suit: Suit.spade),
Card(rank: Rank.ten, suit: Suit.spade),
Card(rank: Rank.nine, suit: Suit.spade),
Card(rank: Rank.eight, suit: Suit.spade),
Card(rank: Rank.seven, suit: Suit.spade),
Card(rank: Rank.six, suit: Suit.spade),
Card(rank: Rank.five, suit: Suit.spade),
Card(rank: Rank.four, suit: Suit.spade),
Card(rank: Rank.trey, suit: Suit.spade),
Card(rank: Rank.deuce, suit: Suit.spade),
],
[
Card(rank: Rank.ace, suit: Suit.heart),
Card(rank: Rank.king, suit: Suit.heart),
Card(rank: Rank.queen, suit: Suit.heart),
Card(rank: Rank.jack, suit: Suit.heart),
Card(rank: Rank.ten, suit: Suit.heart),
Card(rank: Rank.nine, suit: Suit.heart),
Card(rank: Rank.eight, suit: Suit.heart),
Card(rank: Rank.seven, suit: Suit.heart),
Card(rank: Rank.six, suit: Suit.heart),
Card(rank: Rank.five, suit: Suit.heart),
Card(rank: Rank.four, suit: Suit.heart),
Card(rank: Rank.trey, suit: Suit.heart),
Card(rank: Rank.deuce, suit: Suit.heart),
],
[
Card(rank: Rank.ace, suit: Suit.diamond),
Card(rank: Rank.king, suit: Suit.diamond),
Card(rank: Rank.queen, suit: Suit.diamond),
Card(rank: Rank.jack, suit: Suit.diamond),
Card(rank: Rank.ten, suit: Suit.diamond),
Card(rank: Rank.nine, suit: Suit.diamond),
Card(rank: Rank.eight, suit: Suit.diamond),
Card(rank: Rank.seven, suit: Suit.diamond),
Card(rank: Rank.six, suit: Suit.diamond),
Card(rank: Rank.five, suit: Suit.diamond),
Card(rank: Rank.four, suit: Suit.diamond),
Card(rank: Rank.trey, suit: Suit.diamond),
Card(rank: Rank.deuce, suit: Suit.diamond),
],
[
Card(rank: Rank.ace, suit: Suit.club),
Card(rank: Rank.king, suit: Suit.club),
Card(rank: Rank.queen, suit: Suit.club),
Card(rank: Rank.jack, suit: Suit.club),
Card(rank: Rank.ten, suit: Suit.club),
Card(rank: Rank.nine, suit: Suit.club),
Card(rank: Rank.eight, suit: Suit.club),
Card(rank: Rank.seven, suit: Suit.club),
Card(rank: Rank.six, suit: Suit.club),
Card(rank: Rank.five, suit: Suit.club),
Card(rank: Rank.four, suit: Suit.club),
Card(rank: Rank.trey, suit: Suit.club),
Card(rank: Rank.deuce, suit: Suit.club),
],
];