Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
scan_section.dart
Go to the documentation of this file.
1import 'package:barcode_scan2/barcode_scan2.dart';
2import 'package:easy_localization/easy_localization.dart';
3import 'package:fluentui_system_icons/fluentui_system_icons.dart';
4import 'package:flutter/material.dart';
5import 'package:flutter_screenutil/flutter_screenutil.dart';
6import '../../../../../../../core/ui/theme/color_palette.dart';
7import 'scan_card.dart';
8
9class ScanSection extends StatefulWidget {
10 final String type;
11 final Function(List<DrumScan>) onScannedDrumsChanged;
12 final Function(bool) onNotApplicableChanged;
13
15 super.key,
16 required this.type,
17 required this.onScannedDrumsChanged,
18 required this.onNotApplicableChanged,
19 });
20
21 @override
22 State<ScanSection> createState() => _ScanSectionState();
23}
24
25class _ScanSectionState extends State<ScanSection> {
26 final List<DrumScan> scannedDrums = [];
27 bool _isNotApplicable = true;
28
29 void _scanDrum() async {
30 final result = await BarcodeScanner.scan();
31
32 setState(() {
33 if (result.rawContent != ""){
34 scannedDrums.add(
36 id: DateTime.now().millisecondsSinceEpoch.toString(),
37 drumCode: 'DRUM-${result.rawContent}',
38 timestamp: DateTime.now(),
39 ),
40 );
41 widget.onScannedDrumsChanged(scannedDrums);
42 }
43 });
44 }
45
47 setState(() {
48 scannedDrums.removeWhere((drum) => drum.id == id);
49 widget.onScannedDrumsChanged(scannedDrums);
50 });
51 }
52
54 setState(() {
56 widget.onNotApplicableChanged(_isNotApplicable);
57 if (_isNotApplicable) {
58 scannedDrums.clear();
59 widget.onScannedDrumsChanged(scannedDrums);
60 }
61 });
62 }
63
64 @override
65 Widget build(BuildContext context) {
66 return Column(
67 crossAxisAlignment: CrossAxisAlignment.start,
68 children: [
69 Row(
70 mainAxisAlignment: MainAxisAlignment.spaceBetween,
71 children: [
72 Text(
73 widget.type == 'recovered' ? 'information.recovered_drums'.tr() : 'information.deposited_drums'.tr(),
74 style: Theme.of(context).textTheme.titleSmall?.copyWith(
76 ),
77 ),
78 Row(
79 children: [
80 Container(
81 padding: EdgeInsets.symmetric(horizontal: 8.sp, vertical: 4.sp),
82 decoration: BoxDecoration(
84 borderRadius: BorderRadius.circular(20),
85 ),
86 child: Text(
87 '${scannedDrums.length} scanned',
88 style: Theme.of(context).textTheme.bodySmall?.copyWith(
90 fontSize: 10.sp,
91 fontWeight: FontWeight.w500,
92 ),
93 ),
94 ),
95 SizedBox(width: 8.sp),
96 InkWell(
98 child: Container(
99 padding: EdgeInsets.symmetric(horizontal: 5.sp, vertical: 1.sp),
100 decoration: BoxDecoration(
102 borderRadius: BorderRadius.circular(20),
103 border: Border.all(
105 width: 1.5,
106 ),
107 boxShadow: _isNotApplicable ? [
108 BoxShadow(
109 color: Colors.black.withValues(alpha: 0.1),
110 blurRadius: 2,
111 offset: const Offset(0, 1),
112 )
113 ] : null,
114 ),
115 child: Row(
116 mainAxisSize: MainAxisSize.min,
117 children: [
118 Icon(
119 _isNotApplicable ? Icons.check_circle : Icons.radio_button_unchecked,
120 size: 14.sp,
121 color: _isNotApplicable ? Colors.white : ColorPalette.grey,
122 ),
123 SizedBox(width: 4.sp),
124 Text(
125 'N/A',
126 style: Theme.of(context).textTheme.bodySmall?.copyWith(
127 color: _isNotApplicable ? Colors.white : ColorPalette.grey,
128 fontSize: 11.sp,
129 fontWeight: FontWeight.w600,
130 ),
131 ),
132 ],
133 ),
134 ),
135 ),
136 ],
137 ),
138 ],
139 ),
140 SizedBox(height: 8.sp),
141 if (!_isNotApplicable) ...[
142 InkWell(
144 child: Container(
145 height: 100.sp,
146 decoration: BoxDecoration(
147 border: Border.all(color: ColorPalette.grey.withValues(alpha:0.2)),
148 borderRadius: BorderRadius.circular(12),
150 ),
151 child: Center(
152 child: Column(
153 mainAxisAlignment: MainAxisAlignment.center,
154 children: [
155 Icon(
156 FluentIcons.qr_code_20_filled,
157 size: 32.sp,
159 ),
160 SizedBox(height: 8.sp),
161 Text(
162 'Tap to scan ${widget.type} drum',
163 style: Theme.of(context).textTheme.bodySmall?.copyWith(
165 fontSize: 13.sp,
166 fontWeight: FontWeight.w500,
167 ),
168 ),
169 ],
170 ),
171 ),
172 ),
173 ),
174 if (scannedDrums.isNotEmpty) ...[
175 const SizedBox(height: 16),
176 ListView.builder(
177 shrinkWrap: true,
178 physics: const NeverScrollableScrollPhysics(),
179 itemCount: scannedDrums.length,
180 itemBuilder: (context, index) {
181 final drum = scannedDrums[index];
182 return ScanCard(
183 drum: drum,
184 onDelete: () => _removeDrum(drum.id),
185 );
186 },
187 ),
188 ],
189 ],
190 ],
191 );
192 }
193}
194
195class DrumScan {
196 final String id;
198 final DateTime timestamp;
199
201 required this.id,
202 required this.drumCode,
203 required this.timestamp
204 });
205}
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
static const lightGreen
static const lightGrey
static const grey
final DateTime timestamp
final String id
final String drumCode
DrumScan({ required this.id, required this.drumCode, required this.timestamp })
const ScanSection({ super.key, required this.type, required this.onScannedDrumsChanged, required this.onNotApplicableChanged, })
override State< ScanSection > createState()
final Function(List< DrumScan >) onScannedDrumsChanged
final Function(bool) onNotApplicableChanged
final String type
final Widget child
final EdgeInsets padding
class Partner String
final Color color
Definition failures.dart:1
void _toggleNotApplicable()
void _removeDrum(String id)
bool _isNotApplicable
class ScanSection extends StatefulWidget scannedDrums
void _scanDrum() async
final VoidCallback onTap
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
style SizedBox(height:2.h)
style Column(crossAxisAlignment:CrossAxisAlignment.end, children:[Container(padding:EdgeInsets.symmetric(horizontal:8.w, vertical:4.h), decoration:BoxDecoration(color:ColorPalette.tiffanyBlue.withValues(alpha:0.1), borderRadius:BorderRadius.circular(12),), child:Text(collection.type ?? '', style:Theme.of(context).textTheme.bodySmall?.copyWith(color:ColorPalette.tiffanyBlue, fontWeight:FontWeight.bold,),),),],)