template.dart 29 KB

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