template.dart 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:io';
  4. import 'dart:ui' as ui;
  5. import 'package:another_flushbar/flushbar.dart';
  6. import 'package:auto_route/auto_route.dart';
  7. import 'package:cached_network_image/cached_network_image.dart';
  8. import 'package:dotted_line/dotted_line.dart';
  9. import 'package:easy_localization/easy_localization.dart';
  10. import 'package:flutter/foundation.dart';
  11. import 'package:flutter/material.dart';
  12. import 'package:flutter/services.dart';
  13. import 'package:flutter_cache_manager/flutter_cache_manager.dart';
  14. import 'package:fluttertoast/fluttertoast.dart';
  15. import 'package:loading_indicator/loading_indicator.dart';
  16. import 'package:lottie/lottie.dart';
  17. import 'package:page_transition/page_transition.dart';
  18. import 'package:photo_view/photo_view.dart';
  19. import 'package:photo_view/photo_view_gallery.dart';
  20. import 'package:telnow_mobile_new/src/api/jwt_token.dart';
  21. import 'package:telnow_mobile_new/src/injector/injector.dart';
  22. import 'package:telnow_mobile_new/src/layouts/auth/qr.dart';
  23. import 'package:telnow_mobile_new/src/storage/sharedpreferences/shared_preferences_manager.dart';
  24. import 'package:telnow_mobile_new/src/utils/U.dart';
  25. import 'package:telnow_mobile_new/src/utils/cache_manager.dart';
  26. import 'package:uuid/uuid.dart';
  27. PreferredSizeWidget appBarTemplate({required BuildContext context, required String title, String icon = 'arrow-left', List<Widget>? action, exc = false}){
  28. return AppBar(
  29. elevation: 0,
  30. bottomOpacity: 0,
  31. backgroundColor: backgroundColor,
  32. leading: GestureDetector(
  33. child: U.iconsax(icon, color: textColor),
  34. onTap: ()=>Navigator.of(context).pop(exc),
  35. ),
  36. titleSpacing: 0,
  37. title: Text(title, style: TextStyle(color: textColor, fontSize: 17, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
  38. actions: action,
  39. );
  40. }
  41. Widget buttonTemplate({double width = double.infinity, double height = 51, required String text, required Function() action, backgroundColor = primaryColor, textColor = Colors.white, borderColor = primaryColor}){
  42. return SizedBox(
  43. width: width,
  44. height: height,
  45. child: ElevatedButton(
  46. style: ButtonStyle(
  47. elevation: WidgetStateProperty.all<double>(0),
  48. backgroundColor: WidgetStateProperty.all<Color>(backgroundColor),
  49. shape: WidgetStateProperty.all<RoundedRectangleBorder>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))),
  50. side: WidgetStateProperty.all<BorderSide>(BorderSide(color: borderColor))
  51. ),
  52. onPressed: ()=>action(),
  53. child: Text(text, style: TextStyle(fontSize: 16, color: textColor, fontWeight: FontWeight.w500)),
  54. ),
  55. );
  56. }
  57. Widget textVertical(String title, String subtitle){
  58. return Column(
  59. crossAxisAlignment: CrossAxisAlignment.start,
  60. children: [
  61. Text(title, style: TextStyle(color: textColor)),
  62. SizedBox(height: 5),
  63. Text(subtitle, style: TextStyle(color: textColor, fontSize: 12, fontWeight: FontWeight.w300)),
  64. ],
  65. );
  66. }
  67. Widget textHorizontal(String title, String subtitle, {double size = 14, double opacity = 1, bool copy = false}){
  68. return Row(
  69. crossAxisAlignment: CrossAxisAlignment.start,
  70. children: [
  71. Text(title, style: TextStyle(color: textColor.withValues(alpha: opacity), fontSize: size)),
  72. Expanded(
  73. child: copy?Row(
  74. mainAxisAlignment: MainAxisAlignment.end,
  75. children: [
  76. Expanded(child: Text(subtitle, style: TextStyle(color: textColor, fontSize: size), maxLines: 3, overflow: TextOverflow.ellipsis, textAlign: TextAlign.end)),
  77. SizedBox(width: 5),
  78. InkWell(
  79. child: Icon(Icons.copy, color: textColor, size: size+2),
  80. onTap: ()async{
  81. await Clipboard.setData(ClipboardData(text: subtitle));
  82. Fluttertoast.showToast(msg: 'link_copied'.tr());
  83. },
  84. ),
  85. ],
  86. ):Text(subtitle, style: TextStyle(color: textColor, fontSize: size), maxLines: 3, overflow: TextOverflow.ellipsis, textAlign: TextAlign.end,),
  87. ),
  88. ],
  89. );
  90. }
  91. Widget divider({opacity = 0.15, EdgeInsetsGeometry padding = const EdgeInsets.only(top: 0)}){
  92. return Padding(
  93. padding: padding,
  94. child: Divider(height: 1, thickness: 1, color: textColor.withValues(alpha: opacity)),
  95. );
  96. }
  97. Widget dashed({double top = 8, double bottom = 8, double left = 0, double right = 0, Color color = textColor, double width = double.infinity}){
  98. return Padding(padding: EdgeInsets.only(top: top, bottom: bottom, left: left, right: right), child: DottedLine(dashColor: color, lineLength: width, dashLength: 5, dashGapLength: 5, lineThickness: 0.15, dashRadius: 1));
  99. }
  100. Widget separator(){
  101. return Container(
  102. color: Color(0xffF3F3F3),
  103. width: double.infinity, height: 8,
  104. );
  105. }
  106. //------------------------------------------------------------------------------
  107. Widget categoryContainer({required BuildContext context, required String iconUrl}){
  108. double size = U.bodyWidth(context)/6;
  109. // String ext = iconUrl.split(".").last;
  110. return Container(
  111. padding: EdgeInsets.all(5),
  112. decoration: BoxDecoration(
  113. color: Colors.white,
  114. borderRadius: BorderRadius.all(Radius.circular(20)),
  115. border: Border.all(width: 0.2, color: Colors.black12),
  116. boxShadow: [BoxShadow(color: Colors.grey.withValues(alpha: 0.3), blurRadius: 2, offset: Offset(0, 2))]
  117. ),
  118. child: Image(image: CachedNetworkImageProvider('$iconUrl?bridge-cache=true', cacheManager: CacheManager(CacheMan.config('$iconUrl?bridge-cache=true'))), width: size, height: size),
  119. );
  120. }
  121. Widget shimmerTopMenu(BuildContext context){
  122. double size = (U.bodyWidth(context)/6)+10;
  123. return Row(
  124. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  125. children: List.generate(4, (index){
  126. return Container(
  127. width: size, height: size,
  128. decoration: BoxDecoration(
  129. color: Colors.black26,
  130. borderRadius: BorderRadius.all(Radius.circular(20)),
  131. ),
  132. );
  133. }),
  134. );
  135. }
  136. //------------------------------------------------------------------------------
  137. Widget requestTiles({required String image, required String title, required String subtitle, bool border = false, double vertical = 16}){
  138. return Container(
  139. margin: EdgeInsets.symmetric(vertical: vertical),
  140. padding: EdgeInsetsDirectional.only(end: border?16:0),
  141. decoration: BoxDecoration(
  142. color: Colors.white,
  143. border: border?Border.all(color: textColor.withValues(alpha: 0.15)):null,
  144. borderRadius: border?BorderRadius.all(Radius.circular(12)):null
  145. ),
  146. child: Row(
  147. children: [
  148. imageTiles(imageUrl: image),
  149. SizedBox(width: 16),
  150. Expanded(
  151. child: Column(
  152. crossAxisAlignment: CrossAxisAlignment.start,
  153. children: [
  154. Text(title, style: TextStyle(color: textColor, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
  155. dashed(),
  156. Text(subtitle, style: TextStyle(color: textColor, fontSize: 13, fontWeight: FontWeight.w300), maxLines: 2, overflow: TextOverflow.ellipsis)
  157. ],
  158. ),
  159. )
  160. ],
  161. ),
  162. );
  163. }
  164. Widget imageTiles({required String imageUrl, double width = 100, double height = 80, double radius = 12}){
  165. return imageUrl != "null" ? Container(
  166. padding: EdgeInsets.fromLTRB(1, 0, 1, 0),
  167. decoration: BoxDecoration(
  168. color: textColor.withValues(alpha: 0.1),
  169. borderRadius: BorderRadius.all(Radius.circular(radius)),
  170. ),
  171. child: Container(
  172. width: width, height: height,
  173. decoration: BoxDecoration(
  174. color: textColor.withValues(alpha: 0.1),
  175. borderRadius: BorderRadius.all(Radius.circular(radius)),
  176. image: DecorationImage(
  177. image: CachedNetworkImageProvider('$imageUrl?bridge-cache=true', cacheManager: CacheManager(CacheMan.config('$imageUrl?bridge-cache=true'))),
  178. fit: BoxFit.cover,
  179. ),
  180. ),
  181. ),
  182. ): Container(
  183. height: height,
  184. width: width,
  185. decoration: BoxDecoration(
  186. color: Colors.black12,
  187. borderRadius: BorderRadius.all(Radius.circular(12.0))
  188. ),
  189. child: Center(child: Text("noImage".tr(), style: TextStyle(fontStyle: FontStyle.italic, fontSize: width<100?10:14, color: Colors.black38), maxLines: 2, overflow: TextOverflow.ellipsis, textAlign: TextAlign.center,)),
  190. );
  191. }
  192. typedef FieldCallback = void Function(String value);
  193. Widget loginFieldTemplate(
  194. {
  195. required String value,
  196. placeholder = '',
  197. required FieldCallback action,
  198. required FieldCallback submit,
  199. isPassword = false
  200. }
  201. ){
  202. TextEditingController controller = TextEditingController()..text = value;
  203. bool hidePass = true;
  204. return SizedBox(
  205. width: double.infinity,
  206. child: StatefulBuilder(
  207. builder: (context, fieldState) => TextFormField(
  208. controller: controller,
  209. style: TextStyle(fontSize: 16, color: Colors.white),
  210. keyboardType: TextInputType.text,
  211. obscureText: isPassword?hidePass:false,
  212. cursorColor: Colors.white,
  213. decoration: InputDecoration(
  214. hintText: placeholder,
  215. hintStyle: TextStyle(fontSize: 16, color: Colors.white.withValues(alpha: 0.6)),
  216. filled: true,
  217. fillColor: Colors.white.withValues(alpha: 0.25),
  218. hoverColor: Colors.white.withValues(alpha: 0.26),
  219. contentPadding: EdgeInsets.all(16),
  220. border: InputBorder.none,
  221. suffixIconConstraints: BoxConstraints(maxHeight: 40, maxWidth: 40, minHeight: 40, minWidth: 40),
  222. suffixIcon: isPassword?GestureDetector(child: U.iconsax(hidePass?'eye':'eye-slash', color: Colors.white.withValues(alpha: 0.6)), onTap: ()=>fieldState(()=>hidePass=!hidePass)):null,
  223. enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Colors.white)),
  224. focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: Colors.white)),
  225. isDense: true
  226. ),
  227. onChanged: (val)=>action(val.toString()),
  228. onFieldSubmitted: (val)=>submit(val.toString()),
  229. ),
  230. ),
  231. );
  232. }
  233. Widget loadingTemplate(VoidCallback setState){
  234. Future.delayed(Duration(seconds: 10),() {
  235. setState();
  236. });
  237. return Center(
  238. child: SizedBox(
  239. height: 36,
  240. child: LoadingIndicator(
  241. indicatorType: Indicator.ballPulseRise,
  242. colors: U.defaultRainbowColors(),
  243. strokeWidth: 2,
  244. backgroundColor: Colors.black.withValues(alpha: 0),
  245. pathBackgroundColor: Colors.black,
  246. ),
  247. ),
  248. );
  249. }
  250. Widget loadingTemplateNoVoid(){
  251. return Center(
  252. child: SizedBox(
  253. height: 36,
  254. child: LoadingIndicator(
  255. indicatorType: Indicator.ballPulseRise,
  256. colors: U.defaultRainbowColors(),
  257. strokeWidth: 2,
  258. backgroundColor: Colors.black.withValues(alpha: 0),
  259. pathBackgroundColor: Colors.black,
  260. ),
  261. ),
  262. );
  263. }
  264. Widget showButton(BuildContext context){
  265. var pid = U.getPidFromUrl(context.router.currentUrl);
  266. return Center(
  267. child: GestureDetector(
  268. onTap: (){
  269. context.router.removeLast();
  270. context.navigateToPath("/app/$pid/login");
  271. },
  272. child: Container(
  273. decoration: BoxDecoration(color: Colors.amber.withAlpha(0)),
  274. height: MediaQuery.of(context).size.height,
  275. width: MediaQuery.of(context).size.width,
  276. child: Center(
  277. child: Column(
  278. mainAxisAlignment: MainAxisAlignment.center,
  279. children: [
  280. Text("failedLoad".tr()),
  281. SizedBox(height: 12,),
  282. Container(
  283. decoration: BoxDecoration(
  284. border: Border.all(color: Color(0xFFA5A5A5)),
  285. borderRadius: BorderRadius.all(Radius.circular(4))
  286. ),
  287. child: Padding(
  288. padding: const EdgeInsets.all(8.0),
  289. child: Text("tap2retry".tr()),
  290. ),
  291. )
  292. ],
  293. )
  294. )
  295. ),
  296. ),
  297. );
  298. }
  299. Widget infoContainer(String text){
  300. return Container(
  301. width: double.infinity,
  302. padding: EdgeInsets.all(12),
  303. decoration: BoxDecoration(
  304. color: secondaryColor.withValues(alpha: 0.1),
  305. border: Border.all(color: secondaryColor),
  306. borderRadius: BorderRadius.all(Radius.circular(12))
  307. ),
  308. child: Text(text, style: TextStyle(color: textColor), textAlign: TextAlign.center),
  309. );
  310. }
  311. class PhotoPreview extends StatelessWidget {
  312. final String title;
  313. final imageUrl;
  314. final bool isUrl;
  315. final bool isNetwork;
  316. const PhotoPreview(this.title, this.imageUrl, this.isUrl, {super.key, this.isNetwork = false});
  317. @override
  318. Widget build(BuildContext context) {
  319. return Scaffold(
  320. backgroundColor: Colors.black,
  321. appBar: AppBar(
  322. elevation: 0,
  323. bottomOpacity: 0,
  324. titleSpacing: 0,
  325. title: Text(title, style: TextStyle(color: Colors.white, fontSize: 17, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
  326. backgroundColor: Colors.black.withValues(alpha: 0.4),
  327. leading: GestureDetector(
  328. child: U.iconsax('arrow-left', color: Colors.white),
  329. onTap: () => Navigator.of(context).pop(),
  330. ),
  331. ),
  332. body: SizedBox(
  333. width: MediaQuery.of(context).size.width,
  334. height: MediaQuery.of(context).size.height,
  335. child: PhotoView(
  336. maxScale: 5.0,
  337. minScale: 0.3,
  338. imageProvider: (isUrl ? NetworkImage(imageUrl) : isNetwork ? MemoryImage(imageUrl) : FileImage(imageUrl)) as ImageProvider<Object>?,
  339. )),
  340. );
  341. }
  342. }
  343. class PhotoPreviewGallery extends StatelessWidget {
  344. final String title;
  345. final List imageList;
  346. final int startIndex;
  347. final bool isUrl;
  348. final String column;
  349. const PhotoPreviewGallery({required this.title, required this.imageList, required this.startIndex, this.isUrl = true, this.column = 'image', super.key});
  350. @override
  351. Widget build(BuildContext context) {
  352. return Scaffold(
  353. backgroundColor: Colors.black,
  354. appBar: AppBar(
  355. title: Text(title, style: TextStyle(fontSize: 18)),
  356. backgroundColor: Colors.black.withValues(alpha: 0.4),
  357. titleSpacing: 0,
  358. leading: IconButton(
  359. icon: Icon(Icons.arrow_back_rounded),
  360. onPressed: () => Navigator.of(context).pop(),
  361. ),
  362. ),
  363. body: SizedBox(
  364. width: MediaQuery.of(context).size.width,
  365. height: MediaQuery.of(context).size.height,
  366. child: PhotoViewGallery.builder(
  367. itemCount: imageList.length,
  368. pageController: PageController(initialPage: startIndex),
  369. builder: (context, index) {
  370. var uuid = Uuid().v1().replaceAll('-', '');
  371. return PhotoViewGalleryPageOptions(
  372. imageProvider: (isUrl ? NetworkImage('${imageList[index][column]}?uuid=$uuid') : imageList[index] is File ? FileImage(imageList[index]) : MemoryImage(imageList[index])) as ImageProvider<Object>?,
  373. maxScale: 5.0, minScale: 0.3,
  374. );
  375. },
  376. )
  377. ),
  378. );
  379. }
  380. }
  381. //------------------------------------------------------------------------------
  382. class MyClipper extends CustomClipper<Path> {
  383. final bool isNip;
  384. MyClipper(this.isNip);
  385. @override
  386. Path getClip(Size size) {
  387. var path = Path();
  388. double factor = 6.0;
  389. path.lineTo(0, size.height - factor);
  390. path.quadraticBezierTo(0, size.height, factor, size.height);
  391. if (isNip) {
  392. path.lineTo(size.width - (factor * 2), size.height);
  393. path.quadraticBezierTo(size.width - factor, size.height, size.width - factor, size.height - factor);
  394. path.lineTo(size.width - factor, factor);
  395. } else {
  396. path.lineTo(size.width - factor, size.height);
  397. path.quadraticBezierTo(size.width, size.height, size.width, size.height - factor);
  398. path.lineTo(size.width, factor);
  399. path.quadraticBezierTo(size.width, 0, size.width - factor, 0);
  400. }
  401. path.lineTo(size.width, 0);
  402. path.lineTo(factor, 0);
  403. path.quadraticBezierTo(0, 0, 0, factor);
  404. return path;
  405. }
  406. @override
  407. bool shouldReclip(CustomClipper oldClipper) => true;
  408. }
  409. class YourClipper extends CustomClipper<Path> {
  410. final bool isNip;
  411. YourClipper(this.isNip);
  412. @override
  413. Path getClip(Size size) {
  414. var path = Path();
  415. double factor = 6.0;
  416. if (isNip) {
  417. path.lineTo(factor, factor);
  418. path.lineTo(factor, size.height - factor);
  419. path.quadraticBezierTo(factor, size.height, factor * 2, size.height);
  420. } else {
  421. path.lineTo(0, size.height - factor);
  422. path.quadraticBezierTo(0, size.height, factor, size.height);
  423. }
  424. path.lineTo(size.width - factor, size.height);
  425. path.quadraticBezierTo(size.width, size.height, size.width, size.height - factor);
  426. path.lineTo(size.width, factor);
  427. path.quadraticBezierTo(size.width, 0, size.width - factor, 0);
  428. if (!isNip) {
  429. path.lineTo(factor, 0);
  430. path.quadraticBezierTo(0, 0, 0, factor);
  431. }
  432. return path;
  433. }
  434. @override
  435. bool shouldReclip(CustomClipper oldClipper) => true;
  436. }
  437. isBase64(value) {
  438. try {
  439. base64Decode(value);
  440. return true;
  441. } catch (e) {
  442. return false;
  443. }
  444. }
  445. //------------------------------------------------------------------------------
  446. class Debouncer {
  447. final int? milliseconds;
  448. VoidCallback? action;
  449. Timer? _timer;
  450. Debouncer({this.milliseconds});
  451. run(VoidCallback action) {
  452. if (null != _timer) {
  453. _timer?.cancel();
  454. }
  455. _timer = Timer(Duration(milliseconds: milliseconds!), action);
  456. }
  457. }
  458. navigateTo(BuildContext context, child){
  459. return Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: child));
  460. }
  461. navigateToThen(BuildContext context, child, act){
  462. Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: child)).then((v) => act());
  463. }
  464. navigateBack(BuildContext context, {exc = false}){
  465. return Navigator.of(context).pop(exc);
  466. }
  467. void showError(BuildContext context, message) {
  468. Flushbar(
  469. message: message,
  470. icon: Icon(
  471. Icons.info_outline,
  472. size: 28.0,
  473. color: Colors.red,
  474. ),
  475. duration: Duration(seconds: 5),
  476. flushbarPosition: FlushbarPosition.BOTTOM,
  477. margin: EdgeInsets.all(8),
  478. borderRadius: BorderRadius.all(Radius.circular(8)),
  479. ).show(context);
  480. }
  481. void showSuccess(context, message) {
  482. Flushbar(
  483. message: message,
  484. icon: Icon(
  485. Icons.info_outline,
  486. size: 28.0,
  487. color: Colors.green,
  488. ),
  489. duration: Duration(seconds: 5),
  490. flushbarPosition: FlushbarPosition.BOTTOM,
  491. margin: EdgeInsets.all(8),
  492. borderRadius: BorderRadius.all(Radius.circular(8)),
  493. ).show(context);
  494. }
  495. String convertDate(date, String locale) {
  496. if (date == "-" || date.isEmpty) {
  497. return date;
  498. }
  499. final dateToCheck = DateTime.parse(date);
  500. final now = DateTime.now();
  501. final today = DateTime(now.year, now.month, now.day);
  502. final yesterday = DateTime(now.year, now.month, now.day - 1);
  503. final aDate = DateTime(dateToCheck.year, dateToCheck.month, dateToCheck.day);
  504. if (aDate == today) {
  505. return '${'today'.tr()} ${DateFormat('HH:mm', locale).format(DateTime.parse(date))}';
  506. } else if (aDate == yesterday) {
  507. return '${'yesterday'.tr()} ${DateFormat('HH:mm', locale).format(DateTime.parse(date))}';
  508. } else {
  509. return DateFormat('dd MMM HH:mm', locale).format(DateTime.parse(date));
  510. }
  511. }
  512. //------------------------------------------------------------------------------
  513. class RefreshPage extends StatelessWidget {
  514. final VoidCallback onRefresh;
  515. const RefreshPage(this.onRefresh, {super.key});
  516. @override
  517. Widget build(BuildContext context) {
  518. return Container(
  519. padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 2.5),
  520. height: MediaQuery.of(context).size.height,
  521. child: Center(
  522. child: GestureDetector(
  523. child: Column(
  524. children: [
  525. Icon(Icons.refresh_rounded, size: 50, color: Colors.grey),
  526. Text('refresh'.tr(), style: TextStyle(color: Colors.grey))
  527. ],
  528. ),
  529. onTap: () => onRefresh(),
  530. ),
  531. ),
  532. );
  533. }
  534. }
  535. //------------------------------------------------------------------------------
  536. final JwtToken token = JwtToken();
  537. final SharedPreferencesManager _sharedPreferencesManager = locator<SharedPreferencesManager>();
  538. class NoDataPage extends StatelessWidget {
  539. const NoDataPage({super.key});
  540. @override
  541. Widget build(BuildContext context) {
  542. return Center(
  543. child: Column(
  544. mainAxisSize: MainAxisSize.min,
  545. children: <Widget>[
  546. kIsWeb && !isCanvasKit ? Container(
  547. width: 150, margin: EdgeInsets.only(top: 20, bottom: 10), padding: EdgeInsets.all(10),
  548. child: Image(image: AssetImage('assets/image/error/EmptyData.png'))
  549. ) : Lottie.asset('assets/image/lottie/Nodata.json', width: 250, height: 250, fit: BoxFit.fill),
  550. Padding(
  551. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  552. child: Text('notFound'.tr(),
  553. style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
  554. textAlign: TextAlign.center),
  555. ),
  556. Padding(
  557. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  558. child: Text('notFound2'.tr(),
  559. style: TextStyle(fontSize: 14), textAlign: TextAlign.center),
  560. )
  561. ],
  562. ),
  563. );
  564. }
  565. }
  566. handlingError(context, type) {
  567. var data = [
  568. {
  569. 'image': 'NoInternet.png',
  570. 'title': 'noInternetTitle'.tr(),
  571. 'description': 'noInternetDesc'.tr()
  572. },
  573. {
  574. 'image': 'ErrorServer.png',
  575. 'title': 'errorServerTitle'.tr(),
  576. 'description': 'errorServerDesc'.tr()
  577. },
  578. {
  579. 'image': 'ErrorConnection.png',
  580. 'title': 'errorConnectTitle'.tr(),
  581. 'description': 'errorConnectDesc'.tr()
  582. },
  583. {
  584. 'image': 'ErrorAuth.png',
  585. 'title': 'invalidAccountTitle'.tr(),
  586. 'description': 'invalidAccountDesc'.tr()
  587. },
  588. {
  589. 'image': 'ErrorAuth.png',
  590. 'title': 'expAccountTitle'.tr(),
  591. 'description': 'expAccountDesc'.tr()
  592. }
  593. ];
  594. showModalBottomSheet<void>(
  595. context: context,
  596. backgroundColor: Colors.white,
  597. isDismissible: false,
  598. enableDrag: false,
  599. builder: (BuildContext context) {
  600. return SingleChildScrollView(
  601. child: Column(
  602. mainAxisSize: MainAxisSize.min,
  603. children: <Widget>[
  604. Container(
  605. padding: const EdgeInsets.fromLTRB(15, 10, 15, 0),
  606. alignment: Alignment.centerRight,
  607. child: GestureDetector(
  608. child: Icon(Icons.clear),
  609. onTap: () => Navigator.of(context).pop(),
  610. ),
  611. ),
  612. Container(
  613. width: 200,
  614. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  615. child: Image(
  616. image: AssetImage('assets/image/error/${data[type]['image']!}'))),
  617. Padding(
  618. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  619. child: Text(data[type]['title']!,
  620. style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
  621. textAlign: TextAlign.center),
  622. ),
  623. Padding(
  624. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  625. child: Text(data[type]['description']!,
  626. style: TextStyle(fontSize: 14),
  627. textAlign: TextAlign.center),
  628. ),
  629. type > 2
  630. ? Padding(
  631. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  632. child: SizedBox(
  633. width: double.infinity,
  634. height: 45,
  635. child: TextButton(
  636. style: ButtonStyle(
  637. backgroundColor:
  638. WidgetStateProperty.all<Color>(primaryColor),
  639. shape: WidgetStateProperty.all<
  640. RoundedRectangleBorder>(
  641. RoundedRectangleBorder(
  642. borderRadius: BorderRadius.circular(5),
  643. ))),
  644. child: Text('logout'.tr().toUpperCase(),
  645. style: TextStyle(color: Colors.white),
  646. textAlign: TextAlign.center),
  647. onPressed: () {
  648. if (type == 4) {
  649. _sharedPreferencesManager.clearKey(
  650. SharedPreferencesManager.keyAccessCode);
  651. _sharedPreferencesManager.clearKey(
  652. SharedPreferencesManager.keySerialCode);
  653. _sharedPreferencesManager.clearKey(
  654. SharedPreferencesManager.keyAccessToken);
  655. _sharedPreferencesManager.clearKey(
  656. SharedPreferencesManager.keyRefreshToken);
  657. _sharedPreferencesManager.clearKey(
  658. SharedPreferencesManager.keyUsername);
  659. _sharedPreferencesManager.clearKey(
  660. SharedPreferencesManager.keyIsLogin);
  661. _sharedPreferencesManager.clearKey(
  662. SharedPreferencesManager.keyScoope);
  663. _sharedPreferencesManager.clearKey(
  664. SharedPreferencesManager.debugString);
  665. _sharedPreferencesManager.clearKey(SharedPreferencesManager.keyHistoryMark);
  666. Navigator.pushAndRemoveUntil(
  667. context,
  668. MaterialPageRoute(
  669. builder: (context) => NewQrPage()),
  670. ModalRoute.withName("/home"));
  671. } else {
  672. var pid = U.getPidFromUrl(context.router.currentUrl);
  673. token.logout();
  674. context.router.removeLast();
  675. context.navigateToPath("/app/$pid/login");
  676. // print(pid);
  677. // context.router.removeLast();
  678. // context.navigateToPath('/app/$pid/login');
  679. }
  680. },
  681. )),
  682. )
  683. : SizedBox(height: 1, width: 1)
  684. ],
  685. ),
  686. );
  687. });
  688. }
  689. // ignore: must_be_immutable
  690. class NoImageFound extends StatelessWidget {
  691. bool show = true;
  692. NoImageFound(this.show, {super.key});
  693. @override
  694. Widget build(BuildContext context) {
  695. return SizedBox(
  696. width: MediaQuery.of(context).size.width - 150,
  697. height: MediaQuery.of(context).size.height / 4,
  698. child: Stack(
  699. fit: StackFit.expand,
  700. children: [
  701. Image.asset('assets/image/general/QrCode.jpg', fit: BoxFit.cover),
  702. ClipRRect(
  703. // Clip it cleanly.
  704. child: BackdropFilter(
  705. filter: ui.ImageFilter.blur(sigmaX: 10, sigmaY: 10),
  706. child: Container(
  707. color: Colors.grey.withValues(alpha: 0.5),
  708. alignment: Alignment.center,
  709. child: show
  710. ? Container(
  711. padding: const EdgeInsets.all(10),
  712. decoration: BoxDecoration(
  713. color: Colors.white24,
  714. borderRadius:
  715. BorderRadius.all(Radius.circular(50))),
  716. child: Text('notFoundImg'.tr(),
  717. style: TextStyle(fontSize: 12)),
  718. )
  719. : Center(
  720. child: CircularProgressIndicator(),
  721. ),
  722. ),
  723. ),
  724. ),
  725. ],
  726. ),
  727. );
  728. }
  729. }
  730. dialogConfirm({required BuildContext context, required String title, required String text, required Function actionYes}){
  731. showDialog(
  732. context: context,
  733. builder: (BuildContext context) {
  734. return AlertDialog(
  735. title: Text(title),
  736. content: Text(text),
  737. actions: <Widget>[
  738. TextButton(
  739. child: Text("buttonNo".tr()),
  740. onPressed: () {
  741. Navigator.of(context).pop();
  742. },
  743. ),
  744. TextButton(
  745. onPressed: (){
  746. Navigator.of(context).pop();
  747. actionYes();
  748. },
  749. child: Text("buttonYes".tr())),
  750. ],
  751. );
  752. },
  753. );
  754. }
  755. showLoading(BuildContext context, {String? text, String? lottie}){
  756. showDialog(
  757. context: context,
  758. barrierDismissible: false,
  759. barrierColor: lottie!=null?Colors.white:null,
  760. builder: (BuildContext context) {
  761. return WillPopScope(
  762. onWillPop: () => Future.value(false),
  763. child: Center(
  764. child: Column(
  765. mainAxisSize: MainAxisSize.min,
  766. children: [
  767. lottie != null ? Lottie.asset('assets/image/lottie/$lottie', width: 250, height: 250, fit: BoxFit.fill) : CircularProgressIndicator(color: primaryColor),
  768. SizedBox(height: 5),
  769. Text(text??'inProcess'.tr(), style: TextStyle(color: lottie!=null?Colors.black:Colors.white))
  770. ],
  771. ),
  772. ),
  773. );
  774. },
  775. );
  776. }
  777. closeLoading(BuildContext context){
  778. Navigator.of(context, rootNavigator: true).pop();
  779. }