forked from fossasia/magic-epaper-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay_card.dart
More file actions
142 lines (137 loc) · 4.36 KB
/
display_card.dart
File metadata and controls
142 lines (137 loc) · 4.36 KB
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
140
141
142
import 'package:flutter/material.dart';
import 'package:magic_epaper_app/constants/color_constants.dart';
import 'package:magic_epaper_app/util/epd/epd.dart';
import 'package:magic_epaper_app/view/widget/color_dot.dart';
class DisplayCard extends StatelessWidget {
final Epd display;
final bool isSelected;
final VoidCallback onTap;
const DisplayCard({
super.key,
required this.display,
required this.isSelected,
required this.onTap,
});
String _getColorName(Color color) {
switch (color) {
case Colors.black:
return 'Black';
case Colors.white:
return 'White';
case Colors.red:
return 'Red';
case Colors.yellow:
return 'Yellow';
case Colors.orange:
return 'Orange';
case Colors.green:
return 'Green';
case Colors.blue:
return 'Blue';
default:
return '';
}
}
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
highlightColor: Colors.redAccent,
borderRadius: BorderRadius.circular(12),
splashColor: Colors.redAccent.withValues(alpha: 0.2),
child: Card(
color: Colors.white,
elevation: isSelected ? 4 : 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(
color: isSelected ? colorPrimary : Colors.grey.shade300,
width: isSelected ? 2 : 1,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(11),
topRight: Radius.circular(11),
),
child: Container(
width: double.infinity,
color: const Color.fromARGB(255, 255, 255, 255),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Image.asset(
display.imgPath,
fit: BoxFit.contain,
height: 160,
errorBuilder: (context, error, stackTrace) {
return Center(
child: Icon(
Icons.display_settings,
size: 60,
color: Colors.grey.shade400,
),
);
},
),
),
),
),
),
Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
display.name,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
const SizedBox(height: 8),
Row(
children: display.colors
.map((color) => ColorDot(color: color))
.toList(),
),
const SizedBox(height: 4),
Text(
display.colors.map(_getColorName).join(', '),
style: const TextStyle(
fontSize: 10,
color: Colors.grey,
),
),
const SizedBox(height: 8),
_buildSpecRow('Model:', display.modelId),
_buildSpecRow(
'Resolution:', '${display.width} × ${display.height}'),
_buildSpecRow('Driver:', display.driverName),
],
),
),
],
),
),
);
}
Widget _buildSpecRow(String label, String value) {
return Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: const TextStyle(fontSize: 10, color: Colors.grey)),
Text(value,
style:
const TextStyle(fontSize: 10, fontWeight: FontWeight.w500)),
],
),
);
}
}