demo_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import 'package:cs_resources/theme/app_colors_theme.dart';
  2. import 'package:cs_resources/theme/theme_config.dart';
  3. import 'package:cs_resources/theme/theme_notifier.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:auto_route/auto_route.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:plugin_basic/basic_export.dart';
  9. import 'package:plugin_basic/provider/user_config/user_config_service.dart';
  10. import 'package:plugin_platform/engine/cache/local_cache_manager.dart';
  11. import 'package:plugin_platform/engine/dialog/dialog_engine.dart';
  12. import 'package:plugin_platform/engine/directory/directory_util.dart';
  13. import 'package:plugin_platform/engine/image/image_preview.dart';
  14. import 'package:plugin_platform/engine/media/image_picker_utils.dart';
  15. import 'package:plugin_platform/engine/notify/notify_engine.dart';
  16. import 'package:plugin_platform/engine/sp/sp_util.dart';
  17. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  18. import 'package:shared/utils/log_utils.dart';
  19. import 'package:widgets/dialog/app_default_dialog.dart';
  20. import 'package:widgets/ext/ex_widget.dart';
  21. import 'package:widgets/my_load_image.dart';
  22. import 'package:widgets/picker/date_picker_util.dart';
  23. import 'package:widgets/picker/option_pick_util.dart';
  24. import 'package:plugin_platform/platform_export.dart';
  25. class DemoPage extends HookConsumerWidget {
  26. const DemoPage({Key? key}) : super(key: key);
  27. @override
  28. Widget build(BuildContext context, WidgetRef ref) {
  29. final _userService = UserConfigService.getInstance(ref: ref);
  30. final _userConfig = UserConfigService.getState(ref: ref);
  31. Log.d("VisitorPage - build 了");
  32. return Scaffold(
  33. appBar: AppBar(title: Text("Visitor"),systemOverlayStyle: ThemeConfig.getSystemUiOverlayStyleByTheme(context)),
  34. backgroundColor: context.appColors.backgroundDefault,
  35. body: Center(
  36. child: Column(
  37. children: [
  38. Row(
  39. mainAxisAlignment: MainAxisAlignment.spaceAround,
  40. children: [
  41. Text("当前的用户:${_userConfig.userName}"),
  42. ElevatedButton(
  43. onPressed: () {
  44. _userService.setUserInfo("张三");
  45. },
  46. child: Text(
  47. '修改用户信息',
  48. ),
  49. ),
  50. ],
  51. ).marginOnly(top: 10),
  52. Row(
  53. mainAxisAlignment: MainAxisAlignment.spaceAround,
  54. children: [
  55. ElevatedButton(
  56. onPressed: () {
  57. // fetchServerTime();
  58. },
  59. child: Text('网络请求'),
  60. ),
  61. ElevatedButton(
  62. onPressed: () {
  63. ToastEngine.show("这是一个吐司气泡");
  64. },
  65. child: Text('吐司/气泡'),
  66. ),
  67. ElevatedButton(
  68. onPressed: () async {
  69. NotifyEngine.showSuccess("操作成功");
  70. await Future.delayed(Duration(seconds: 3));
  71. NotifyEngine.showFailure("操作失败");
  72. await Future.delayed(Duration(seconds: 3));
  73. NotifyEngine.showError("操作错误");
  74. },
  75. child: Text('成功/失败通知'),
  76. ),
  77. ],
  78. ).marginOnly(top: 10),
  79. Row(
  80. mainAxisAlignment: MainAxisAlignment.spaceAround,
  81. children: [
  82. ElevatedButton(
  83. onPressed: () {
  84. DialogEngine.show(
  85. widget: AppDefaultDialog(
  86. //这种布局自己自定义去
  87. title: "提示",
  88. message: "默认的弹窗,自定义的弹窗自己画去",
  89. confirmAction: () {
  90. ToastEngine.show("点击了确定");
  91. },
  92. ));
  93. },
  94. child: Text('弹窗'),
  95. ),
  96. ElevatedButton(
  97. onPressed: () {
  98. DateTime dateTime = DateTime.now();
  99. DatePickerUtil.showCupertinoDatePicker(
  100. mode: CupertinoDatePickerMode.date,
  101. selectedDateTime: dateTime,
  102. onDateTimeChanged: (date) {
  103. dateTime = date;
  104. },
  105. title: "选择日期",
  106. );
  107. },
  108. child: Text('时间选择'),
  109. ),
  110. ElevatedButton(
  111. onPressed: () {
  112. OptionPickerUtil.showCupertinoOptionPicker(
  113. items: ["前天", "昨天", "今天", "明天", "后天"],
  114. initialSelectIndex: 0,
  115. onPickerChanged: (_, index) {
  116. ToastEngine.show("选中的索引为:$index");
  117. },
  118. );
  119. },
  120. child: Text('条件选择'),
  121. ),
  122. ],
  123. ).marginOnly(top: 10),
  124. Row(
  125. mainAxisAlignment: MainAxisAlignment.spaceAround,
  126. children: [
  127. ElevatedButton(
  128. onPressed: () {
  129. ImagePickerUtils().show(context, (filePath) {
  130. ToastEngine.show("图片的路径为:$filePath");
  131. });
  132. },
  133. child: Text('相册/相册'),
  134. ),
  135. ElevatedButton(
  136. onPressed: () async {
  137. final PermissionStatus permissionStatus = await Permission.phone.request();
  138. if (permissionStatus.isGranted) {
  139. final Uri launchUri = Uri(
  140. scheme: 'tel',
  141. path: "+8618571458165",
  142. );
  143. await launchUrl(launchUri);
  144. } else {
  145. // 权限被拒绝
  146. ToastEngine.show('Phone call permission denied');
  147. }
  148. },
  149. child: Text('App动态权限'),
  150. ),
  151. ],
  152. ).marginOnly(top: 10),
  153. Row(
  154. mainAxisAlignment: MainAxisAlignment.spaceAround,
  155. children: [
  156. ElevatedButton(
  157. onPressed: () async {
  158. final tempPath = DirectoryUtil.getTempPath();
  159. final docPath = DirectoryUtil.getAppDocPath();
  160. final appSupportPath = DirectoryUtil.getAppSupportPath();
  161. final storagePath = DirectoryUtil.getStoragePath(); //只能拿沙盒路径,外置SD卡是拿不到的
  162. final cacheSize = await DirectoryUtil.getAppCacheSize();
  163. Log.d("沙盒路径 - tempPath:$tempPath docPath:$docPath appSupportPath:$appSupportPath storagePath:$storagePath "
  164. "cacheSize:$cacheSize");
  165. },
  166. child: Text('沙盒路径'),
  167. ),
  168. ElevatedButton(
  169. onPressed: () async {
  170. //Key-Value的重要信息持久化缓存(只存小东西如配置,token)
  171. await SPUtil.putBool("isVip", true);
  172. final isVip = SPUtil.getBool("isVip", defValue: false);
  173. Log.d("存入并取出SP的值 - isVip:$isVip");
  174. //沙盒缓存文件缓存(可存入对象,大文本,Json,网络请求数据)
  175. await localCache.put("name", "李四", expiry: const Duration(seconds: 10));
  176. await localCache.put("age", 28, expiry: const Duration(seconds: 10));
  177. await localCache.put("gender", 1);
  178. await localCache.put("skills", ["游泳", "跑步", "编程"]);
  179. await localCache.put("json", {"code": "200", "msg": "Success", "data": 2});
  180. String? name = await localCache.get("name");
  181. int? age = await localCache.get("age");
  182. int? gender = await localCache.get("gender");
  183. List<String>? skills = await localCache.get("skills");
  184. Map<String, dynamic>? json = await localCache.get("json");
  185. Log.d("获取缓存name:$name");
  186. Log.d("获取缓存age:$age");
  187. Log.d("获取缓存gender:$gender");
  188. Log.d("获取缓存skills:$skills");
  189. Log.d("获取缓存json:$json");
  190. },
  191. child: Text('缓存用法'),
  192. ),
  193. ElevatedButton(
  194. onPressed: () {},
  195. child: Text('图片预览'),
  196. ),
  197. ],
  198. ).marginOnly(top: 10),
  199. Row(
  200. mainAxisAlignment: MainAxisAlignment.spaceAround,
  201. children: [
  202. ElevatedButton(
  203. onPressed: () {},
  204. child: Text('图片加载'),
  205. ),
  206. Hero(
  207. tag: '112cc8a34e13',
  208. child: MyLoadImage("https://pic.quanjing.com/cz/8s/QJ8856274343.jpg@%21794ws", width: 80, height: 80),
  209. ),
  210. ElevatedButton(
  211. onPressed: () {
  212. //单图预览,支持hero
  213. ImagePreviewEngine.singleImagePreview(context, "https://pic.quanjing.com/cz/8s/QJ8856274343.jpg@%21794ws", heroTag: '112cc8a34e13');
  214. //多图预览,支持hero
  215. // ImagePreviewEngine.multipleImagePreview(context, "https://pic.quanjing.com/cz/8s/QJ8856274343.jpg@%21794ws");
  216. },
  217. child: Text('图片预览'),
  218. ),
  219. ],
  220. ).marginOnly(top: 10),
  221. Row(
  222. mainAxisAlignment: MainAxisAlignment.spaceAround,
  223. children: [
  224. ElevatedButton(
  225. onPressed: () {
  226. ref.read(themeProvider.notifier).toggleTheme();
  227. },
  228. child: Text('手动切换主题'),
  229. style: ButtonStyle(
  230. backgroundColor: WidgetStateProperty.all<Color>(context.appColors.btnBgDefault),
  231. // 设置按钮的背景颜色
  232. foregroundColor: WidgetStateProperty.all<Color>(Colors.white),
  233. // 设置按钮文字的颜色
  234. shadowColor: WidgetStateProperty.all<Color>(context.appColors.btnBgDefault),
  235. // 按钮阴影颜色
  236. elevation: WidgetStateProperty.all<double>(5),
  237. // 按钮阴影的高度
  238. shape: WidgetStateProperty.all<RoundedRectangleBorder>(
  239. RoundedRectangleBorder(
  240. borderRadius: BorderRadius.circular(30), // 圆角边框
  241. ),
  242. ),
  243. ),
  244. ),
  245. ElevatedButton(
  246. onPressed: () {
  247. ref.read(themeProvider.notifier).followSystemTheme();
  248. },
  249. child: Text('跟随系统主题'),
  250. style: ButtonStyle(
  251. backgroundColor: WidgetStateProperty.all<Color>(context.appColors.btnBgDefault),
  252. // 设置按钮的背景颜色
  253. foregroundColor: WidgetStateProperty.all<Color>(Colors.white),
  254. // 设置按钮文字的颜色
  255. shadowColor: WidgetStateProperty.all<Color>(context.appColors.btnBgDefault),
  256. // 按钮阴影颜色
  257. elevation: WidgetStateProperty.all<double>(5),
  258. // 按钮阴影的高度
  259. shape: WidgetStateProperty.all<RoundedRectangleBorder>(
  260. RoundedRectangleBorder(
  261. borderRadius: BorderRadius.circular(30), // 圆角边框
  262. ),
  263. ),
  264. ),
  265. ),
  266. ],
  267. ).marginOnly(top: 10),
  268. ],
  269. ),
  270. ),
  271. );
  272. }
  273. }