template.dart 29 KB

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