InitScreen.dart 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // 初始化界面
  2. import 'dart:ffi';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/services.dart';
  6. import '../basic/Method.dart';
  7. import '../basic/Test.dart';
  8. import 'AppScreen.dart';
  9. import 'LoginScreen.dart';
  10. import '../basic/Global.dart' as glob;
  11. import '../basic/Encrypt.dart';
  12. class InitScreen extends StatefulWidget {
  13. const InitScreen({Key? key}) : super(key: key);
  14. @override
  15. State<StatefulWidget> createState() => _InitScreenState();
  16. }
  17. class _InitScreenState extends State<InitScreen> {
  18. var _authenticating = false;
  19. @override
  20. initState() {
  21. _init();
  22. super.initState();
  23. }
  24. Future<dynamic> _init() async {
  25. encryptTest();
  26. await glob.init();
  27. await method.init();
  28. if (_authenticating) {
  29. _goAuthentication();
  30. } else {
  31. _goApplication();
  32. }
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. if (_authenticating) {
  37. return Scaffold(
  38. appBar: AppBar(
  39. title: const Text("身份验证"),
  40. ),
  41. body: Center(
  42. child: Container(
  43. padding: const EdgeInsets.all(20),
  44. child: MaterialButton(
  45. onPressed: () {
  46. _goAuthentication();
  47. },
  48. child:
  49. const Text('您在之前使用APP时开启了身份验证, 请点这段文字进行身份核查, 核查通过后将会进入APP'),
  50. ),
  51. ),
  52. ),
  53. );
  54. }
  55. return const Scaffold(
  56. backgroundColor: Colors.white,
  57. /*body: ConstrainedBox(
  58. constraints: const BoxConstraints.expand(),
  59. child: Image.asset(
  60. "lib/assets/init.jpg",
  61. fit: BoxFit.contain,
  62. ),
  63. ),*/
  64. );
  65. }
  66. Future _goApplication() async {
  67. // 登录, 如果token失效重新登录, 网络不好的时候可能需要1分钟
  68. // Todo: 直接进入AppScreen
  69. if (await method.authorized) {
  70. // 如果token或username+password有效则直接进入登录好的界面
  71. Navigator.pushReplacement(
  72. context,
  73. MaterialPageRoute(builder: (context) => const AppScreen()),
  74. );
  75. } else {
  76. // 否则跳转到登录页
  77. Navigator.pushReplacement(
  78. context,
  79. MaterialPageRoute(builder: (context) => const LoginScreen()),
  80. );
  81. }
  82. }
  83. Future _goAuthentication() async {
  84. _goApplication();
  85. }
  86. }