init_view.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:track_common/view/login/login_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. Get.offNamed(LoginView.name);
  17. }
  18. }
  19. }
  20. class InitView extends GetView<InitController> {
  21. const InitView({super.key});
  22. static const name = '/InitView';
  23. @override
  24. Widget build(BuildContext context) {
  25. return Scaffold(
  26. body: Obx(() => Text('${controller._use}',
  27. style: const TextStyle(color: Colors.transparent))));
  28. }
  29. }
  30. // class _State extends State<InitView> {
  31. // @override
  32. // Widget build(BuildContext context) {
  33. // return const Scaffold(body: Center());
  34. // }
  35. //
  36. // void init() async {
  37. // await allInit();
  38. // await 1.seconds.delay();
  39. //
  40. //
  41. //
  42. //
  43. // try {
  44. //
  45. // await api.ApiService.to.stub.toMapListV2(api.MapListRequestV2());
  46. // Get.offAll(() => const HomeView(), binding: HomeView.bindings());
  47. // } catch (e) {
  48. // LoginView.to(
  49. // canBack: false,
  50. // thenToPageCall: () {
  51. // Get.offAll(() => const HomeView(), binding: HomeView.bindings());
  52. // });
  53. // }
  54. // }
  55. //
  56. // @override
  57. // void initState() {
  58. // super.initState();
  59. //
  60. // init();
  61. // }
  62. // }