-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
artifact_card.dart
119 lines (111 loc) · 3.49 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
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';
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;
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,
}) : 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,
}) : 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,
}) : 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: Styles.mainCardShape,
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),
),
Tooltip(
message: name,
child: Text(
name,
textAlign: TextAlign.center,
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);
}
}