[toc]
一、生命周期
该界面前提:
①、StatefulWidget
②、WidgetsBindingObserver
③、@override didChangeAppLifecycleState
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:background_fetch/background_fetch.dart'; void main() { runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => new _MyAppState(); } class _MyAppState extends State<MyApp> with WidgetsBindingObserver{ @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); } @override void didChangeAppLifecycleState(AppLifecycleState state) { super.didChangeAppLifecycleState(state);
print("--" + state.toString()); switch (state) { case AppLifecycleState.inactive: break; case AppLifecycleState.resumed: break; case AppLifecycleState.paused: break; case AppLifecycleState.detached: break; } } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override Widget build(BuildContext context) { return new MaterialApp( home: new Scaffold( appBar: new AppBar( title: const Text('前后台测试') ), body: Container( color: Colors.black, child: Text('前后台测试'), ), ), ); } }
|
1、什么时候渲染完成?
使用场景:
二、路由