init_view.dart 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:track_common/view.dart';
  4. abstract class InitController extends GetxController {
  5. Future<bool> isNeedLogin();
  6. Future<void> allInit();
  7. final _use = true.obs;
  8. @override
  9. void onInit() {
  10. super.onInit();
  11. init();
  12. }
  13. Future<void> init() async {
  14. await allInit();
  15. if (await isNeedLogin()) {
  16. LoginView.to(
  17. canBack: false,
  18. thenToPageCall: () {
  19. Get.offAllNamed(HomeView.name);
  20. });
  21. } else {
  22. Get.offAllNamed(HomeView.name);
  23. }
  24. }
  25. }
  26. class InitView extends GetView<InitController> {
  27. const InitView({super.key});
  28. static const name = '/InitView';
  29. @override
  30. Widget build(BuildContext context) {
  31. return Scaffold(
  32. body: Obx(() => Text('${controller._use}',
  33. style: const TextStyle(color: Colors.transparent))));
  34. }
  35. }
  36. // class _State extends State<InitView> {
  37. // @override
  38. // Widget build(BuildContext context) {
  39. // return const Scaffold(body: Center());
  40. // }
  41. //
  42. // void init() async {
  43. // await allInit();
  44. // await 1.seconds.delay();
  45. //
  46. //
  47. //
  48. //
  49. // try {
  50. //
  51. // await api.ApiService.to.stub.toMapListV2(api.MapListRequestV2());
  52. // Get.offAll(() => const HomeView(), binding: HomeView.bindings());
  53. // } catch (e) {
  54. // LoginView.to(
  55. // canBack: false,
  56. // thenToPageCall: () {
  57. // Get.offAll(() => const HomeView(), binding: HomeView.bindings());
  58. // });
  59. // }
  60. // }
  61. //
  62. // @override
  63. // void initState() {
  64. // super.initState();
  65. //
  66. // init();
  67. // }
  68. // }