demo_page.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import 'dart:io';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  5. import 'package:ftrecruiter/comm/constants/color_constants.dart';
  6. import 'package:ftrecruiter/comm/utils/dark_theme_util.dart';
  7. import 'package:ftrecruiter/comm/utils/log_utils.dart';
  8. import 'package:ftrecruiter/comm/widget/common_widget.dart';
  9. import 'package:ftrecruiter/comm/widget/my_button.dart';
  10. import 'package:ftrecruiter/modules/zdemo/demo_controller.dart';
  11. import 'package:get/get.dart';
  12. class DemoPage extends StatelessWidget {
  13. DemoPage({Key? key}) : super(key: key);
  14. final controller = Get.put(DemoController(apiRepository: Get.find()));
  15. @override
  16. Widget build(BuildContext context) {
  17. return Scaffold(
  18. backgroundColor: DarkThemeUtil.multiColors(ColorConstants.white),
  19. appBar: CommonWidget.appBar(context, "Demo"),
  20. body: Container(
  21. width: double.infinity,
  22. height: double.infinity,
  23. child: ListView(
  24. shrinkWrap: true,
  25. padding: const EdgeInsets.symmetric(horizontal: 30.0),
  26. children: [
  27. CommonWidget.rowHeight(height: 15),
  28. GetBuilder<DemoController>(builder: (controller) {
  29. return Text(obtainTextStr(controller.status) ?? "-");
  30. }),
  31. //第一个按钮
  32. TextButton(
  33. style: ButtonStyle(
  34. minimumSize: MaterialStateProperty.all<Size>(const Size(200, 45)), // 设置最小宽度和高度
  35. backgroundColor: MaterialStateProperty.all<Color>(Colors.redAccent),
  36. ),
  37. onPressed: () {
  38. controller.increase();
  39. // controller.getServerTime2();
  40. // controller.getIndustry2();
  41. // controller.complicatedFetch();
  42. controller.getUserInfo();
  43. },
  44. child: Obx(() {
  45. return Text(
  46. "当前数量:${controller.count}",
  47. style: const TextStyle(fontSize: 16, color: Colors.white),
  48. );
  49. })),
  50. CommonWidget.rowHeight(height: 15),
  51. MyButton(
  52. fontSize: 16,
  53. textColor: Colors.black,
  54. text: "My Button的封装按钮",
  55. backgroundColor: ColorConstants.gray,
  56. onPressed: () {
  57. controller.getLocalFile('test_avatar.jpeg').then((File file) {
  58. // 在此处处理文件对象
  59. var list = file.readAsBytesSync();
  60. SmartDialog.compatible.showToast("file:${file.parent}");
  61. Log.e("file:${file.path} list:$list");
  62. });
  63. },
  64. radius: 15,
  65. enableOverlay: false,
  66. //禁用水波纹
  67. side: BorderSide(color: Colors.black, width: 1.0),
  68. ),
  69. CommonWidget.rowHeight(height: 15),
  70. MyButton(
  71. text: "顺序调用接口,先登录后获取",
  72. backgroundColor: DarkThemeUtil.multiColors(ColorConstants.dividerColor, darkColor: Colors.deepOrange),
  73. radius: 20,
  74. elevation: 5.0,
  75. onPressed: () {
  76. controller.getUserInfo();
  77. },
  78. ),
  79. ],
  80. )),
  81. );
  82. }
  83. String? obtainTextStr(RxStatus status) {
  84. if (status.isLoading) {
  85. return "Loading...";
  86. } else if (status.isSuccess) {
  87. return "Success";
  88. } else if (status.isEmpty) {
  89. return "Empty";
  90. } else if (status.isError) {
  91. return status.errorMessage;
  92. }
  93. return "";
  94. }
  95. }