main.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import 'package:dio/dio.dart';
  2. import 'package:flustars/flustars.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. void main() => runApp(new MyApp());
  6. class MyApp extends StatefulWidget {
  7. @override
  8. _MyAppState createState() => new _MyAppState();
  9. }
  10. class _MyAppState extends State<MyApp> {
  11. String _userName = '';
  12. @override
  13. void initState() {
  14. super.initState();
  15. test();
  16. }
  17. void test() async {
  18. print("SpUtil: " + SpUtil.isInitialized().toString());
  19. SpUtil spUtil = await SpUtil.getInstance();
  20. //SpUtil.remove("username");
  21. print("SpUtil: " + SpUtil.isInitialized().toString());
  22. SpUtil.putString("username", "sky24");
  23. print("username: " + SpUtil.getString("username").toString());
  24. if (!mounted) return;
  25. setState(() {
  26. _userName = SpUtil.getString("username");
  27. });
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return new MaterialApp(
  32. home: new MainPage(),
  33. );
  34. // return new MaterialApp(
  35. // home: new Scaffold(
  36. // appBar: new AppBar(
  37. // title: const Text('Plugin example app'),
  38. // ),
  39. // body: new Center(
  40. // child: new Text('username: $_userName'),
  41. // ),
  42. // floatingActionButton: new FloatingActionButton(onPressed: () {
  43. // Navigator.push(
  44. // context, new CupertinoPageRoute(builder: (ctx) => TestPage()));
  45. // }),
  46. // ),
  47. // );
  48. }
  49. }
  50. class MainPage extends StatefulWidget {
  51. @override
  52. State<StatefulWidget> createState() {
  53. return new MainPageState();
  54. }
  55. }
  56. class MainPageState extends State<MainPage> {
  57. WidgetUtil widgetUtil = new WidgetUtil();
  58. @override
  59. void initState() {
  60. super.initState();
  61. DioUtil.openDebug(); //打开debug模式
  62. Options options = DioUtil.getDefOptions();
  63. options.baseUrl = "http://www.wanandroid.com/";
  64. HttpConfig config = new HttpConfig(options: options);
  65. DioUtil().setConfig(config);
  66. DioUtil()
  67. .request<List>(Method.get, "banner/json")
  68. .then((BaseResp<List> resp) {
  69. print("BaseResp: " + resp.toString());
  70. });
  71. widgetUtil.asyncPrepares(true, (_) {
  72. print("Widget 渲染完成...");
  73. });
  74. }
  75. @override
  76. Widget build(BuildContext context) {
  77. double width = ScreenUtil().screenWidth;
  78. double height = ScreenUtil().screenHeight;
  79. double density = ScreenUtil.getInstance().screenDensity;
  80. double tempW = ScreenUtil.getInstance().getWidth(360.0);
  81. double tempH = ScreenUtil().getHeight(360.0);
  82. print(
  83. "width: $width, height: $height, density: $density, tempW: $tempW, tempH: $tempH");
  84. double _width = width * density;
  85. double _height = height * density;
  86. double __tempW = ScreenUtil.getInstance().getWidthPx(90.0);
  87. print(
  88. "_width: $_width, height: $_height, __tempW: $__tempW, tempW: $tempW, tempH: $tempH");
  89. return new Scaffold(
  90. appBar: new AppBar(),
  91. body: new Column(
  92. crossAxisAlignment: CrossAxisAlignment.start,
  93. children: <Widget>[
  94. new Container(
  95. width: 360.0,
  96. height: 50,
  97. color: Colors.grey,
  98. child: new Center(
  99. child: new Text(
  100. "你好你好你好",
  101. style: new TextStyle(fontSize: 24.0),
  102. ),
  103. ),
  104. ),
  105. new Container(
  106. width: ScreenUtil.getInstance().getWidth(360.0),
  107. height: 50,
  108. color: Colors.grey,
  109. child: new Center(
  110. child: new Text(
  111. "你好你好你好",
  112. style: new TextStyle(fontSize: 24.0),
  113. ),
  114. ),
  115. ),
  116. new Container(
  117. width: 100,
  118. height: 100,
  119. color: Colors.grey,
  120. child: new Center(
  121. child: new Text(
  122. "你好你好你好",
  123. style: new TextStyle(fontSize: 24.0),
  124. ),
  125. ),
  126. ),
  127. new Container(
  128. margin: EdgeInsets.only(top: 10.0),
  129. width: ScreenUtil.getInstance().getWidth(100.0),
  130. height: ScreenUtil.getInstance().getHeight(100.0),
  131. color: Colors.grey,
  132. child: new Center(
  133. child: new Text(
  134. "你好你好你好",
  135. style: new TextStyle(fontSize: 24.0),
  136. ),
  137. ),
  138. ),
  139. new Container(
  140. margin: EdgeInsets.only(top: 10.0),
  141. width: ScreenUtil.getInstance().getWidth(100.0),
  142. height: ScreenUtil.getInstance().getHeight(100.0),
  143. color: Colors.grey,
  144. child: new Center(
  145. child: new Text(
  146. "你好你好你好",
  147. style: new TextStyle(
  148. fontSize: ScreenUtil.getInstance().getSp(24.0)),
  149. ),
  150. ),
  151. ),
  152. ],
  153. ),
  154. );
  155. }
  156. }
  157. class TestPage extends StatefulWidget {
  158. @override
  159. State<StatefulWidget> createState() {
  160. return new TestPageState();
  161. }
  162. }
  163. class TestPageState extends State<TestPage> {
  164. @override
  165. Widget build(BuildContext context) {
  166. double width = ScreenUtil.getInstance().screenWidth;
  167. double height = ScreenUtil.getInstance().screenHeight;
  168. print("width: $width, height: $height");
  169. return new Scaffold(
  170. body: new AppBar(),
  171. );
  172. }
  173. }