main.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import 'package:flutter/material.dart';
  2. import 'package:link/route/LinkMiddleWare.dart';
  3. import 'package:link/route/routes.dart';
  4. import 'package:link/utils/api.dart';
  5. import 'package:link/utils/global.dart';
  6. import 'package:link/utils/http_utils.dart';
  7. import 'dart:js' as js;
  8. import 'package:get/get.dart';
  9. import 'package:link/utils/storage.dart';
  10. import 'package:link/view/begin_add_link.dart';
  11. import 'package:link/view/edit.dart';
  12. import 'package:link/view/index.dart';
  13. import 'package:link/view/notfound.dart';
  14. import 'package:link/view/welcome.dart';
  15. import 'package:url_strategy/url_strategy.dart';
  16. Future<void> main() async {
  17. WidgetsFlutterBinding.ensureInitialized();
  18. await initStore();
  19. setPathUrlStrategy();
  20. runApp(const MyApp());
  21. }
  22. Future<void> initStore() async {
  23. HttpUtils.init(baseUrl: Api.baseUrl);
  24. await StorageUtil().init();
  25. if (StorageUtil().prefs!.getString("token") != null){
  26. Global().token = StorageUtil().prefs!.getString("token")!;
  27. Global().hasLogin = true;
  28. }
  29. }
  30. RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
  31. // class MyApp extends StatelessWidget {
  32. // const MyApp({Key? key}) : super(key: key);
  33. // // This widget is the root of your application.
  34. // @override
  35. // Widget build(BuildContext context) {
  36. // Global().routeObserver = routeObserver;
  37. // return GetMaterialApp(
  38. // title: 'Link Everything',
  39. // debugShowCheckedModeBanner: false,
  40. // navigatorObservers: [routeObserver],
  41. // theme: ThemeData(
  42. // fontFamily: 'Apple',
  43. // primarySwatch: Colors.blue,
  44. // ),
  45. // onGenerateRoute: RouteGenerator.generateRoute,
  46. // );
  47. // }
  48. // }
  49. class MyApp extends StatelessWidget {
  50. const MyApp({Key? key}) : super(key: key);
  51. // This widget is the root of your application.
  52. @override
  53. Widget build(BuildContext context) {
  54. Global().routeObserver = routeObserver;
  55. return GetMaterialApp(
  56. title: 'Link Everything',
  57. debugShowCheckedModeBanner: false,
  58. navigatorObservers: [routeObserver],
  59. routingCallback: (routing){
  60. if (routing!.current=='/EditScreen'){
  61. // Get.to(()=>const NotFoundPage());
  62. }
  63. // print('aaa');
  64. },
  65. // unknownRoute: GetPage(name: '/', page: ()=>const IndexScreen()),
  66. // unknownRoute: GetPage(name: '/notfound', page: ()=>const NotFoundPage()),
  67. theme: ThemeData(
  68. // This is the theme of your application.
  69. //
  70. // Try running your application with "flutter run". You'll see the
  71. // application has a blue toolbar. Then, without quitting the app, try
  72. // changing the primarySwatch below to Colors.green and then invoke
  73. // "hot reload" (press "r" in the console where you ran "flutter run",
  74. // or simply save your changes to "hot reload" in a Flutter IDE).
  75. // Notice that the counter didn't reset back to zero; the application
  76. // is not restarted.
  77. fontFamily: 'Apple',
  78. primarySwatch: Colors.blue,
  79. ),
  80. // home: const BeginAddLink(),
  81. // home: const IndexScreen(),
  82. getPages: routes.pages,
  83. // routingCallback: () async {
  84. // },
  85. // home: const MyHomePage(title: 'Flutter Demo Home Page'),
  86. );
  87. }
  88. }
  89. class MyHomePage extends StatefulWidget {
  90. const MyHomePage({Key? key, required this.title}) : super(key: key);
  91. // This widget is the home page of your application. It is stateful, meaning
  92. // that it has a State object (defined below) that contains fields that affect
  93. // how it looks.
  94. // This class is the configuration for the state. It holds the values (in this
  95. // case the title) provided by the parent (in this case the App widget) and
  96. // used by the build method of the State. Fields in a Widget subclass are
  97. // always marked "final".
  98. final String title;
  99. @override
  100. State<MyHomePage> createState() => _MyHomePageState();
  101. }
  102. class _MyHomePageState extends State<MyHomePage> {
  103. int _counter = 0;
  104. void _incrementCounter() {
  105. js.context.callMethod('alertMessage',['hi']);
  106. setState(() {
  107. // This call to setState tells the Flutter framework that something has
  108. // changed in this State, which causes it to rerun the build method below
  109. // so that the display can reflect the updated values. If we changed
  110. // _counter without calling setState(), then the build method would not be
  111. // called again, and so nothing would appear to happen.
  112. _counter++;
  113. });
  114. }
  115. @override
  116. Widget build(BuildContext context) {
  117. // This method is rerun every time setState is called, for instance as done
  118. // by the _incrementCounter method above.
  119. //
  120. // The Flutter framework has been optimized to make rerunning build methods
  121. // fast, so that you can just rebuild anything that needs updating rather
  122. // than having to individually change instances of widgets.
  123. return Scaffold(
  124. appBar: AppBar(
  125. // Here we take the value from the MyHomePage object that was created by
  126. // the App.build method, and use it to set our appbar title.
  127. title: Text(widget.title),
  128. ),
  129. body: Center(
  130. // Center is a layout widget. It takes a single child and positions it
  131. // in the middle of the parent.
  132. child: Column(
  133. // Column is also a layout widget. It takes a list of children and
  134. // arranges them vertically. By default, it sizes itself to fit its
  135. // children horizontally, and tries to be as tall as its parent.
  136. //
  137. // Invoke "debug painting" (press "p" in the console, choose the
  138. // "Toggle Debug Paint" action from the Flutter Inspector in Android
  139. // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
  140. // to see the wireframe for each widget.
  141. //
  142. // Column has various properties to control how it sizes itself and
  143. // how it positions its children. Here we use mainAxisAlignment to
  144. // center the children vertically; the main axis here is the vertical
  145. // axis because Columns are vertical (the cross axis would be
  146. // horizontal).
  147. mainAxisAlignment: MainAxisAlignment.center,
  148. children: <Widget>[
  149. const Text(
  150. 'You have pushed the button this many times:',
  151. ),
  152. Text(
  153. '$_counter',
  154. style: Theme.of(context).textTheme.headline4,
  155. ),
  156. ],
  157. ),
  158. ),
  159. floatingActionButton: FloatingActionButton(
  160. onPressed: _incrementCounter,
  161. tooltip: 'Increment',
  162. child: const Icon(Icons.add),
  163. ), // This trailing comma makes auto-formatting nicer for build methods.
  164. );
  165. }
  166. }