main.dart 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import 'package:flustars/flustars.dart';
  2. import 'package:flutter/material.dart';
  3. void main() => runApp(new MyApp());
  4. class MyApp extends StatefulWidget {
  5. @override
  6. _MyAppState createState() => new _MyAppState();
  7. }
  8. class _MyAppState extends State<MyApp> {
  9. String _userName = '';
  10. @override
  11. void initState() {
  12. super.initState();
  13. test();
  14. }
  15. void test() async {
  16. print("SpUtil: " + SpUtil.isInitialized().toString());
  17. SpUtil spUtil = await SpUtil.getInstance();
  18. //SpUtil.remove("username");
  19. print("SpUtil: " + SpUtil.isInitialized().toString());
  20. SpUtil.putString("username", "sky24");
  21. print("username: " + SpUtil.getString("username").toString());
  22. if (!mounted) return;
  23. setState(() {
  24. _userName = SpUtil.getString("username");
  25. });
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return new MaterialApp(
  30. home: new Scaffold(
  31. appBar: new AppBar(
  32. title: const Text('Plugin example app'),
  33. ),
  34. body: new Center(
  35. child: new Text('username: $_userName'),
  36. ),
  37. ),
  38. );
  39. }
  40. }