Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
documents_button.dart
Go to the documentation of this file.
1import 'package:connect/core/localization/app_localizations.dart';
2import 'package:connect/core/utils/pdf_util.dart';
3import 'package:connect/features/account/domain/entities/document_model.dart';
4import 'package:hugeicons/hugeicons.dart';
5
6import '/core/router/routes.dart';
7import '/core/ui/theme/color_palette.dart';
8import 'package:flutter/material.dart';
9import 'package:flutter_screenutil/flutter_screenutil.dart';
10import 'package:go_router/go_router.dart';
11
12class DocumentsButton extends StatelessWidget {
14 super.key,
15 required this.document,
16 });
17
19
20 @override
21 Widget build(BuildContext context) {
22 return Container(
23 decoration: BoxDecoration(
24 color: Theme.of(context).colorScheme.surface,
25 borderRadius: BorderRadius.circular(12.sp),
26 boxShadow: [
27 BoxShadow(
28 color: Colors.black.withOpacity(0.05),
29 blurRadius: 8,
30 offset: const Offset(0, 2),
31 ),
32 ],
33 border: Border.all(
34 color: Colors.grey.withOpacity(0.2),
35 width: 1,
36 ),
37 ),
38 child: Material(
39 color: Colors.transparent,
40 child: InkWell(
41 borderRadius: BorderRadius.circular(12.sp),
42 onTap: () {
43 _showDocumentDetailsDialog(context);
44 },
45 child: Padding(
46 padding: EdgeInsets.all(10.sp),
47 child: Row(
48 children: [
49 Container(
50 width: 32.sp,
51 height: 32.sp,
52 decoration: BoxDecoration(
53 color:
54 Theme.of(context).colorScheme.primary.withOpacity(0.1),
55 borderRadius: BorderRadius.circular(6.sp),
56 ),
57 child: Icon(
58 HugeIcons.strokeRoundedPdf01,
59 color: Theme.of(context).colorScheme.primary,
60 size: 18.sp,
61 ),
62 ),
63 SizedBox(width: 8.sp),
64 Expanded(
65 child: Column(
66 crossAxisAlignment: CrossAxisAlignment.start,
67 mainAxisAlignment: MainAxisAlignment.center,
68 children: [
69 Text(
70 document.name,
71 style: Theme.of(context).textTheme.bodySmall?.copyWith(
72 fontWeight: FontWeight.bold,
73 ),
74 maxLines: 1,
75 overflow: TextOverflow.ellipsis,
76 ),
77 SizedBox(height: 2.sp),
78 Text(
79 AppLocalizations.of(context).translate('Tap to view'),
80 style: Theme.of(context).textTheme.bodySmall?.copyWith(
81 color: Colors.grey,
82 fontSize: 9.sp,
83 ),
84 ),
85 ],
86 ),
87 ),
88 Icon(
89 Icons.arrow_forward_ios_rounded,
90 size: 12.sp,
91 color: Colors.grey,
92 ),
93 ],
94 ),
95 ),
96 ),
97 ),
98 );
99 }
100
101 void _showDocumentDetailsDialog(BuildContext context) {
102 showDialog(
103 context: context,
104 builder: (BuildContext context) {
105 return Dialog(
106 backgroundColor: Theme.of(context).colorScheme.surface,
107 shape: RoundedRectangleBorder(
108 borderRadius: BorderRadius.circular(16.sp),
109 ),
110 child: Padding(
111 padding: EdgeInsets.all(20.sp),
112 child: Column(
113 mainAxisSize: MainAxisSize.min,
114 crossAxisAlignment: CrossAxisAlignment.start,
115 children: [
116 Row(
117 children: [
118 Container(
119 width: 40.sp,
120 height: 40.sp,
121 decoration: BoxDecoration(
122 color: Theme.of(context)
123 .colorScheme
124 .primary
125 .withOpacity(0.1),
126 borderRadius: BorderRadius.circular(8.sp),
127 ),
128 child: Icon(
129 HugeIcons.strokeRoundedPdf01,
130 color: Theme.of(context).colorScheme.primary,
131 size: 24.sp,
132 ),
133 ),
134 SizedBox(width: 12.sp),
135 Expanded(
136 child: Text(
137 document.name,
138 style:
139 Theme.of(context).textTheme.titleMedium?.copyWith(
140 fontWeight: FontWeight.bold,
141 ),
142 ),
143 ),
144 ],
145 ),
146 SizedBox(height: 20.sp),
148 context,
149 AppLocalizations.of(context).translate('File Name'),
150 document.pdfFileName),
151 SizedBox(height: 8.sp),
153 context,
154 AppLocalizations.of(context).translate('File Type'),
155 document.extension),
156 SizedBox(height: 20.sp),
157 Row(
158 mainAxisAlignment: MainAxisAlignment.end,
159 children: [
160 TextButton(
161 onPressed: () {
162 Navigator.of(context).pop();
163 },
164 child: Text(
165 AppLocalizations.of(context).translate('Close'),
166 style: TextStyle(
167 color: Colors.grey,
168 ),
169 ),
170 ),
171 SizedBox(width: 8.sp),
172 ElevatedButton(
173 onPressed: () async {
174 Navigator.of(context).pop();
175 try {
176 // Show loading indicator
177 ScaffoldMessenger.of(context).showSnackBar(
178 SnackBar(
179 content: Text(
180 AppLocalizations.of(context)
181 .translate('Opening PDF'),
182 ),
183 ),
184 );
185
186 // Open the PDF
188 document.attachmentDocument,
189 document.pdfFileName,
190 );
191 } catch (e) {
192 // Show error message
193 ScaffoldMessenger.of(context).showSnackBar(
194 SnackBar(
195 content: Text(
197 'Error opening pdf file try again'),
198 )),
199 );
200 }
201 },
202 style: ElevatedButton.styleFrom(
203 backgroundColor: Theme.of(context).colorScheme.primary,
204 foregroundColor: Theme.of(context).colorScheme.surface,
205 padding: EdgeInsets.symmetric(
206 horizontal: 15.sp, vertical: 12.sp),
207 shape: RoundedRectangleBorder(
208 borderRadius: BorderRadius.circular(80.sp),
209 ),
210 ),
211 child: Text(
212 AppLocalizations.of(context).translate('Open PDF'),
213 ),
214 ),
215 ],
216 ),
217 ],
218 ),
219 ),
220 );
221 },
222 );
223 }
224
225 Widget _buildInfoRow(BuildContext context, String label, String value) {
226 return Row(
227 crossAxisAlignment: CrossAxisAlignment.start,
228 children: [
229 SizedBox(
230 width: 80.sp,
231 child: Text(
232 '$label:',
233 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
234 color: Colors.grey,
235 ),
236 ),
237 ),
238 SizedBox(width: 8.sp),
239 Expanded(
240 child: Text(
241 value,
242 style: Theme.of(context).textTheme.bodyMedium,
243 ),
244 ),
245 ],
246 );
247 }
248}
String translate(String key)
static AppLocalizations of(BuildContext context)
static Future< String > openBase64Pdf(String base64String, String fileName) async
Converts base64 string to PDF file and opens it.
Definition pdf_util.dart:12
const DocumentsButton({ super.key, required this.document, })
final VoidCallback onPressed
final VoidCallback onTap
void _showDocumentDetailsDialog(BuildContext context)
final DocumentModel document
final Widget child
Widget _buildInfoRow(BuildContext context, String label, String value)
override Widget build(BuildContext context)
final String label
final Color backgroundColor