-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
artifact_card.dart
139 lines (130 loc) · 4.25 KB
/
artifact_card.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import 'package:flutter/material.dart';
import 'package:shiori/domain/models/models.dart';
import 'package:shiori/presentation/artifact/artifact_page.dart';
import 'package:shiori/presentation/shared/extensions/rarity_extensions.dart';
import 'package:shiori/presentation/shared/gradient_card.dart';
import 'package:shiori/presentation/shared/images/rarity.dart';
import 'package:shiori/presentation/shared/styles.dart';
import 'package:transparent_image/transparent_image.dart';
import 'artifact_stats.dart';
final replaceDigitRegex = RegExp(r'\d{1}');
class ArtifactCard extends StatelessWidget {
final String keyName;
final String name;
final String image;
final int rarity;
final List<ArtifactCardBonusModel> bonus;
final double imgWidth;
final double imgHeight;
final bool withoutDetails;
final bool withElevation;
final bool isInSelectionMode;
final bool withShape;
final bool withTextOverflow;
const ArtifactCard({
Key? key,
required this.keyName,
required this.name,
required this.image,
required this.rarity,
required this.bonus,
this.imgWidth = 140,
this.imgHeight = 120,
this.withElevation = true,
this.isInSelectionMode = false,
this.withShape = true,
this.withTextOverflow = false,
}) : withoutDetails = false,
super(key: key);
const ArtifactCard.withoutDetails({
Key? key,
required this.keyName,
required this.name,
required this.image,
required this.rarity,
this.isInSelectionMode = false,
this.imgWidth = 70,
this.imgHeight = 60,
this.withShape = true,
this.withTextOverflow = false,
}) : bonus = const [],
withoutDetails = true,
withElevation = false,
super(key: key);
ArtifactCard.item({
Key? key,
required ArtifactCardModel item,
this.imgWidth = 140,
this.imgHeight = 120,
this.withElevation = true,
this.withoutDetails = false,
this.isInSelectionMode = false,
this.withShape = true,
this.withTextOverflow = false,
}) : keyName = item.key,
name = item.name,
image = item.image,
rarity = item.rarity,
bonus = item.bonus,
super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return InkWell(
borderRadius: Styles.mainCardBorderRadius,
onTap: () => _gotoDetailPage(context),
child: GradientCard(
clipBehavior: Clip.hardEdge,
shape: withShape ? Styles.mainCardShape : null,
elevation: withElevation ? Styles.cardTenElevation : 0,
gradient: rarity.getRarityGradient(),
child: Padding(
padding: withoutDetails ? Styles.edgeInsetAll5 : Styles.edgeInsetAll10,
child: Column(
children: [
FadeInImage(
width: imgWidth,
height: imgHeight,
placeholder: MemoryImage(kTransparentImage),
image: AssetImage(image),
imageErrorBuilder: (context, error, stack) {
//This can happen when trying to load sets like 'Prayer to xxx'
final path = image.replaceFirst(replaceDigitRegex, '4');
return Image.asset(
path,
width: imgWidth,
height: imgHeight,
);
},
),
Tooltip(
message: name,
child: Text(
name,
textAlign: TextAlign.center,
overflow: withTextOverflow ? TextOverflow.ellipsis : null,
style: theme.textTheme.subtitle1!.copyWith(fontWeight: FontWeight.bold, color: Colors.white),
),
),
Rarity(stars: rarity),
if (bonus.isNotEmpty)
ArtifactStats(
bonus: bonus,
textColor: Colors.white,
maxLines: 10,
),
],
),
),
),
);
}
Future<void> _gotoDetailPage(BuildContext context) async {
if (isInSelectionMode) {
Navigator.pop(context, keyName);
return;
}
final route = MaterialPageRoute(builder: (ctx) => ArtifactPage(itemKey: keyName));
await Navigator.of(context).push(route);
}
}