main.dart 4.7 KB

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