template.dart 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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: loadingTemplateNoVoid()
  241. ),
  242. );
  243. }
  244. Widget loadingTemplateNoVoid(){
  245. return Center(
  246. child: SizedBox(
  247. height: 36,
  248. child: LoadingIndicator(
  249. indicatorType: Indicator.ballClipRotatePulse,
  250. colors: U.loadingIndicatorColors(),
  251. strokeWidth: 2,
  252. backgroundColor: Colors.black.withValues(alpha: 0),
  253. pathBackgroundColor: Colors.black,
  254. ),
  255. ),
  256. );
  257. }
  258. Widget showButton(BuildContext context){
  259. var pid = U.getPidFromUrl(context.router.currentUrl);
  260. return Center(
  261. child: GestureDetector(
  262. onTap: (){
  263. context.router.removeLast();
  264. context.navigateToPath("/app/$pid/login");
  265. },
  266. child: Container(
  267. decoration: BoxDecoration(color: Colors.amber.withAlpha(0)),
  268. height: MediaQuery.of(context).size.height,
  269. width: MediaQuery.of(context).size.width,
  270. child: Center(
  271. child: Column(
  272. mainAxisAlignment: MainAxisAlignment.center,
  273. children: [
  274. Text("failedLoad".tr()),
  275. SizedBox(height: 12,),
  276. Container(
  277. decoration: BoxDecoration(
  278. border: Border.all(color: Color(0xFFA5A5A5)),
  279. borderRadius: BorderRadius.all(Radius.circular(4))
  280. ),
  281. child: Padding(
  282. padding: const EdgeInsets.all(8.0),
  283. child: Text("tap2retry".tr()),
  284. ),
  285. )
  286. ],
  287. )
  288. )
  289. ),
  290. ),
  291. );
  292. }
  293. Widget infoContainer(String text){
  294. return Container(
  295. width: double.infinity,
  296. padding: EdgeInsets.all(12),
  297. decoration: BoxDecoration(
  298. color: secondaryColor.withValues(alpha: 0.1),
  299. border: Border.all(color: secondaryColor),
  300. borderRadius: BorderRadius.all(Radius.circular(12))
  301. ),
  302. child: Text(text, style: TextStyle(color: textColor), textAlign: TextAlign.center),
  303. );
  304. }
  305. class PhotoPreview extends StatelessWidget {
  306. final String title;
  307. final imageUrl;
  308. final bool isUrl;
  309. final bool isNetwork;
  310. const PhotoPreview(this.title, this.imageUrl, this.isUrl, {super.key, this.isNetwork = false});
  311. @override
  312. Widget build(BuildContext context) {
  313. return Scaffold(
  314. backgroundColor: Colors.black,
  315. appBar: AppBar(
  316. elevation: 0,
  317. bottomOpacity: 0,
  318. titleSpacing: 0,
  319. title: Text(title, style: TextStyle(color: Colors.white, fontSize: 17, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
  320. backgroundColor: Colors.black.withValues(alpha: 0.4),
  321. leading: GestureDetector(
  322. child: U.iconsax('arrow-left', color: Colors.white),
  323. onTap: () => Navigator.of(context).pop(),
  324. ),
  325. ),
  326. body: SizedBox(
  327. width: MediaQuery.of(context).size.width,
  328. height: MediaQuery.of(context).size.height,
  329. child: PhotoView(
  330. maxScale: 5.0,
  331. minScale: 0.3,
  332. imageProvider: (isUrl ? NetworkImage(imageUrl) : isNetwork ? MemoryImage(imageUrl) : FileImage(imageUrl)) as ImageProvider<Object>?,
  333. )),
  334. );
  335. }
  336. }
  337. class PhotoPreviewGallery extends StatelessWidget {
  338. final String title;
  339. final List imageList;
  340. final int startIndex;
  341. final bool isUrl;
  342. final String column;
  343. const PhotoPreviewGallery({required this.title, required this.imageList, required this.startIndex, this.isUrl = true, this.column = 'image', super.key});
  344. @override
  345. Widget build(BuildContext context) {
  346. return Scaffold(
  347. backgroundColor: Colors.black,
  348. appBar: AppBar(
  349. title: Text(title, style: TextStyle(fontSize: 18)),
  350. backgroundColor: Colors.black.withValues(alpha: 0.4),
  351. titleSpacing: 0,
  352. leading: IconButton(
  353. icon: Icon(Icons.arrow_back_rounded),
  354. onPressed: () => Navigator.of(context).pop(),
  355. ),
  356. ),
  357. body: SizedBox(
  358. width: MediaQuery.of(context).size.width,
  359. height: MediaQuery.of(context).size.height,
  360. child: PhotoViewGallery.builder(
  361. itemCount: imageList.length,
  362. pageController: PageController(initialPage: startIndex),
  363. builder: (context, index) {
  364. var uuid = Uuid().v1().replaceAll('-', '');
  365. return PhotoViewGalleryPageOptions(
  366. imageProvider: (isUrl ? NetworkImage('${imageList[index][column]}?uuid=$uuid') : imageList[index] is File ? FileImage(imageList[index]) : MemoryImage(imageList[index])) as ImageProvider<Object>?,
  367. maxScale: 5.0, minScale: 0.3,
  368. );
  369. },
  370. )
  371. ),
  372. );
  373. }
  374. }
  375. //------------------------------------------------------------------------------
  376. class MyClipper extends CustomClipper<Path> {
  377. final bool isNip;
  378. MyClipper(this.isNip);
  379. @override
  380. Path getClip(Size size) {
  381. var path = Path();
  382. double factor = 6.0;
  383. path.lineTo(0, size.height - factor);
  384. path.quadraticBezierTo(0, size.height, factor, size.height);
  385. if (isNip) {
  386. path.lineTo(size.width - (factor * 2), size.height);
  387. path.quadraticBezierTo(size.width - factor, size.height, size.width - factor, size.height - factor);
  388. path.lineTo(size.width - factor, factor);
  389. } else {
  390. path.lineTo(size.width - factor, size.height);
  391. path.quadraticBezierTo(size.width, size.height, size.width, size.height - factor);
  392. path.lineTo(size.width, factor);
  393. path.quadraticBezierTo(size.width, 0, size.width - factor, 0);
  394. }
  395. path.lineTo(size.width, 0);
  396. path.lineTo(factor, 0);
  397. path.quadraticBezierTo(0, 0, 0, factor);
  398. return path;
  399. }
  400. @override
  401. bool shouldReclip(CustomClipper oldClipper) => true;
  402. }
  403. class YourClipper extends CustomClipper<Path> {
  404. final bool isNip;
  405. YourClipper(this.isNip);
  406. @override
  407. Path getClip(Size size) {
  408. var path = Path();
  409. double factor = 6.0;
  410. if (isNip) {
  411. path.lineTo(factor, factor);
  412. path.lineTo(factor, size.height - factor);
  413. path.quadraticBezierTo(factor, size.height, factor * 2, size.height);
  414. } else {
  415. path.lineTo(0, size.height - factor);
  416. path.quadraticBezierTo(0, size.height, factor, size.height);
  417. }
  418. path.lineTo(size.width - factor, size.height);
  419. path.quadraticBezierTo(size.width, size.height, size.width, size.height - factor);
  420. path.lineTo(size.width, factor);
  421. path.quadraticBezierTo(size.width, 0, size.width - factor, 0);
  422. if (!isNip) {
  423. path.lineTo(factor, 0);
  424. path.quadraticBezierTo(0, 0, 0, factor);
  425. }
  426. return path;
  427. }
  428. @override
  429. bool shouldReclip(CustomClipper oldClipper) => true;
  430. }
  431. isBase64(value) {
  432. try {
  433. base64Decode(value);
  434. return true;
  435. } catch (e) {
  436. return false;
  437. }
  438. }
  439. //------------------------------------------------------------------------------
  440. class Debouncer {
  441. final int? milliseconds;
  442. VoidCallback? action;
  443. Timer? _timer;
  444. Debouncer({this.milliseconds});
  445. run(VoidCallback action) {
  446. if (null != _timer) {
  447. _timer?.cancel();
  448. }
  449. _timer = Timer(Duration(milliseconds: milliseconds!), action);
  450. }
  451. }
  452. navigateTo(BuildContext context, child){
  453. return Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: child));
  454. }
  455. navigateToThen(BuildContext context, child, act){
  456. Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: child)).then((v) => act());
  457. }
  458. navigateBack(BuildContext context, {exc = false}){
  459. return Navigator.of(context).pop(exc);
  460. }
  461. void showError(BuildContext context, message) {
  462. Flushbar(
  463. message: message,
  464. icon: Icon(
  465. Icons.info_outline,
  466. size: 28.0,
  467. color: Colors.red,
  468. ),
  469. duration: Duration(seconds: 5),
  470. flushbarPosition: FlushbarPosition.BOTTOM,
  471. margin: EdgeInsets.all(8),
  472. borderRadius: BorderRadius.all(Radius.circular(8)),
  473. ).show(context);
  474. }
  475. void showSuccess(context, message) {
  476. Flushbar(
  477. message: message,
  478. icon: Icon(
  479. Icons.info_outline,
  480. size: 28.0,
  481. color: Colors.green,
  482. ),
  483. duration: Duration(seconds: 5),
  484. flushbarPosition: FlushbarPosition.BOTTOM,
  485. margin: EdgeInsets.all(8),
  486. borderRadius: BorderRadius.all(Radius.circular(8)),
  487. ).show(context);
  488. }
  489. String convertDate(date, String locale) {
  490. if (date == "-" || date.isEmpty) {
  491. return date;
  492. }
  493. final dateToCheck = DateTime.parse(date);
  494. final now = DateTime.now();
  495. final today = DateTime(now.year, now.month, now.day);
  496. final yesterday = DateTime(now.year, now.month, now.day - 1);
  497. final aDate = DateTime(dateToCheck.year, dateToCheck.month, dateToCheck.day);
  498. if (aDate == today) {
  499. return '${'today'.tr()} ${DateFormat('HH:mm', locale).format(DateTime.parse(date))}';
  500. } else if (aDate == yesterday) {
  501. return '${'yesterday'.tr()} ${DateFormat('HH:mm', locale).format(DateTime.parse(date))}';
  502. } else {
  503. return DateFormat('dd MMM HH:mm', locale).format(DateTime.parse(date));
  504. }
  505. }
  506. //------------------------------------------------------------------------------
  507. class RefreshPage extends StatelessWidget {
  508. final VoidCallback onRefresh;
  509. const RefreshPage(this.onRefresh, {super.key});
  510. @override
  511. Widget build(BuildContext context) {
  512. return Container(
  513. padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 2.5),
  514. height: MediaQuery.of(context).size.height,
  515. child: Center(
  516. child: GestureDetector(
  517. child: Column(
  518. children: [
  519. Icon(Icons.refresh_rounded, size: 50, color: Colors.grey),
  520. Text('refresh'.tr(), style: TextStyle(color: Colors.grey))
  521. ],
  522. ),
  523. onTap: () => onRefresh(),
  524. ),
  525. ),
  526. );
  527. }
  528. }
  529. //------------------------------------------------------------------------------
  530. final JwtToken token = JwtToken();
  531. final SharedPreferencesManager _sharedPreferencesManager = locator<SharedPreferencesManager>();
  532. class NoDataPage extends StatelessWidget {
  533. const NoDataPage({super.key});
  534. @override
  535. Widget build(BuildContext context) {
  536. return Center(
  537. child: Column(
  538. mainAxisSize: MainAxisSize.min,
  539. children: <Widget>[
  540. kIsWeb && !isCanvasKit ? Container(
  541. width: 150, margin: EdgeInsets.only(top: 20, bottom: 10), padding: EdgeInsets.all(10),
  542. child: Image(image: AssetImage('assets/image/error/EmptyData.png'))
  543. ) : Lottie.asset('assets/image/lottie/Nodata.json', width: 250, height: 250, fit: BoxFit.fill),
  544. Padding(
  545. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  546. child: Text('notFound'.tr(),
  547. style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
  548. textAlign: TextAlign.center),
  549. ),
  550. Padding(
  551. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  552. child: Text('notFound2'.tr(),
  553. style: TextStyle(fontSize: 14), textAlign: TextAlign.center),
  554. )
  555. ],
  556. ),
  557. );
  558. }
  559. }
  560. handlingError(context, type) {
  561. var data = [
  562. {
  563. 'image': 'NoInternet.png',
  564. 'title': 'noInternetTitle'.tr(),
  565. 'description': 'noInternetDesc'.tr()
  566. },
  567. {
  568. 'image': 'ErrorServer.png',
  569. 'title': 'errorServerTitle'.tr(),
  570. 'description': 'errorServerDesc'.tr()
  571. },
  572. {
  573. 'image': 'ErrorConnection.png',
  574. 'title': 'errorConnectTitle'.tr(),
  575. 'description': 'errorConnectDesc'.tr()
  576. },
  577. {
  578. 'image': 'ErrorAuth.png',
  579. 'title': 'invalidAccountTitle'.tr(),
  580. 'description': 'invalidAccountDesc'.tr()
  581. },
  582. {
  583. 'image': 'ErrorAuth.png',
  584. 'title': 'expAccountTitle'.tr(),
  585. 'description': 'expAccountDesc'.tr()
  586. }
  587. ];
  588. showModalBottomSheet<void>(
  589. context: context,
  590. backgroundColor: Colors.white,
  591. isDismissible: false,
  592. enableDrag: false,
  593. builder: (BuildContext context) {
  594. return SingleChildScrollView(
  595. child: Column(
  596. mainAxisSize: MainAxisSize.min,
  597. children: <Widget>[
  598. Container(
  599. padding: const EdgeInsets.fromLTRB(15, 10, 15, 0),
  600. alignment: Alignment.centerRight,
  601. child: GestureDetector(
  602. child: Icon(Icons.clear),
  603. onTap: () => Navigator.of(context).pop(),
  604. ),
  605. ),
  606. Container(
  607. width: 200,
  608. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  609. child: Image(
  610. image: AssetImage('assets/image/error/${data[type]['image']!}'))),
  611. Padding(
  612. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  613. child: Text(data[type]['title']!,
  614. style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
  615. textAlign: TextAlign.center),
  616. ),
  617. Padding(
  618. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  619. child: Text(data[type]['description']!,
  620. style: TextStyle(fontSize: 14),
  621. textAlign: TextAlign.center),
  622. ),
  623. type > 2
  624. ? Padding(
  625. padding: const EdgeInsets.fromLTRB(15, 0, 15, 10),
  626. child: SizedBox(
  627. width: double.infinity,
  628. height: 45,
  629. child: TextButton(
  630. style: ButtonStyle(
  631. backgroundColor:
  632. WidgetStateProperty.all<Color>(primaryColor),
  633. shape: WidgetStateProperty.all<
  634. RoundedRectangleBorder>(
  635. RoundedRectangleBorder(
  636. borderRadius: BorderRadius.circular(5),
  637. ))),
  638. child: Text('logout'.tr().toUpperCase(),
  639. style: TextStyle(color: Colors.white),
  640. textAlign: TextAlign.center),
  641. onPressed: () {
  642. if (type == 4) {
  643. _sharedPreferencesManager.clearKey(
  644. SharedPreferencesManager.keyAccessCode);
  645. _sharedPreferencesManager.clearKey(
  646. SharedPreferencesManager.keySerialCode);
  647. _sharedPreferencesManager.clearKey(
  648. SharedPreferencesManager.keyAccessToken);
  649. _sharedPreferencesManager.clearKey(
  650. SharedPreferencesManager.keyRefreshToken);
  651. _sharedPreferencesManager.clearKey(
  652. SharedPreferencesManager.keyUsername);
  653. _sharedPreferencesManager.clearKey(
  654. SharedPreferencesManager.keyIsLogin);
  655. _sharedPreferencesManager.clearKey(
  656. SharedPreferencesManager.keyScoope);
  657. _sharedPreferencesManager.clearKey(
  658. SharedPreferencesManager.debugString);
  659. _sharedPreferencesManager.clearKey(SharedPreferencesManager.keyHistoryMark);
  660. Navigator.pushAndRemoveUntil(
  661. context,
  662. MaterialPageRoute(
  663. builder: (context) => NewQrPage()),
  664. ModalRoute.withName("/home"));
  665. } else {
  666. var pid = U.getPidFromUrl(context.router.currentUrl);
  667. token.logout();
  668. context.router.removeLast();
  669. context.navigateToPath("/app/$pid/login");
  670. // print(pid);
  671. // context.router.removeLast();
  672. // context.navigateToPath('/app/$pid/login');
  673. }
  674. },
  675. )),
  676. )
  677. : SizedBox(height: 1, width: 1)
  678. ],
  679. ),
  680. );
  681. });
  682. }
  683. // ignore: must_be_immutable
  684. class NoImageFound extends StatelessWidget {
  685. bool show = true;
  686. NoImageFound(this.show, {super.key});
  687. @override
  688. Widget build(BuildContext context) {
  689. return SizedBox(
  690. width: MediaQuery.of(context).size.width - 150,
  691. height: MediaQuery.of(context).size.height / 4,
  692. child: Stack(
  693. fit: StackFit.expand,
  694. children: [
  695. Image.asset('assets/image/general/QrCode.jpg', fit: BoxFit.cover),
  696. ClipRRect(
  697. // Clip it cleanly.
  698. child: BackdropFilter(
  699. filter: ui.ImageFilter.blur(sigmaX: 10, sigmaY: 10),
  700. child: Container(
  701. color: Colors.grey.withValues(alpha: 0.5),
  702. alignment: Alignment.center,
  703. child: show
  704. ? Container(
  705. padding: const EdgeInsets.all(10),
  706. decoration: BoxDecoration(
  707. color: Colors.white24,
  708. borderRadius:
  709. BorderRadius.all(Radius.circular(50))),
  710. child: Text('notFoundImg'.tr(),
  711. style: TextStyle(fontSize: 12)),
  712. )
  713. : Center(
  714. child: CircularProgressIndicator(),
  715. ),
  716. ),
  717. ),
  718. ),
  719. ],
  720. ),
  721. );
  722. }
  723. }
  724. dialogConfirm({required BuildContext context, required String title, required String text, required Function actionYes}){
  725. showDialog(
  726. context: context,
  727. builder: (BuildContext context) {
  728. return AlertDialog(
  729. title: Text(title),
  730. content: Text(text),
  731. actions: <Widget>[
  732. TextButton(
  733. child: Text("buttonNo".tr()),
  734. onPressed: () {
  735. Navigator.of(context).pop();
  736. },
  737. ),
  738. TextButton(
  739. onPressed: (){
  740. Navigator.of(context).pop();
  741. actionYes();
  742. },
  743. child: Text("buttonYes".tr())),
  744. ],
  745. );
  746. },
  747. );
  748. }
  749. showLoading(BuildContext context, {String? text, String? lottie}){
  750. showDialog(
  751. context: context,
  752. barrierDismissible: false,
  753. barrierColor: lottie!=null?Colors.white:null,
  754. builder: (BuildContext context) {
  755. return WillPopScope(
  756. onWillPop: () => Future.value(false),
  757. child: Center(
  758. child: Column(
  759. mainAxisSize: MainAxisSize.min,
  760. children: [
  761. lottie != null ? Lottie.asset('assets/image/lottie/$lottie', width: 250, height: 250, fit: BoxFit.fill) : CircularProgressIndicator(color: primaryColor),
  762. SizedBox(height: 5),
  763. Text(text??'inProcess'.tr(), style: TextStyle(color: lottie!=null?Colors.black:Colors.white))
  764. ],
  765. ),
  766. ),
  767. );
  768. },
  769. );
  770. }
  771. closeLoading(BuildContext context){
  772. Navigator.of(context, rootNavigator: true).pop();
  773. }