flutter

flutter cheatsheet

paulaner80 2019. 10. 29. 11:25
반응형



provider

Provider  

 The most basic form of provider. It takes a value and exposes it, whatever the value is.

 ListenableProvider

 A specific provider for Listenable object. ListenableProvider will listen to the object and ask widgets which depend on it to rebuild whenever the listener is called.

 ChangeNotifierProvider

 A specification of ListenableProvider for ChangeNotifier. It will automatically call ChangeNotifier.dispose when needed.

 ValueListenableProvider

 Listen to a ValueListenable and only expose ValueListenable.value.

 StreamProvider

 Listen to a Stream and expose the latest value emitted.

 FutureProvider

 Takes a Future and updates dependents when the future completes.

 ListenableProxyProvider

 A variation of ListenableProvider that builds its value from values obtained from other providers.

 ProxyProvider 

  A provider that builds a value based on other providers.

 snackbar

 

ScaffoldMessenger.
of(context).
showSnackBar(
SnackBar(
      content: const Text('snack'),
        duration: const Duration(seconds: 1),
     ));


 bottomNavigationBar 
return Scaffold(
appBar: AppBar(
title:const Text("sample")
),
body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: BottomNavigationBar(
items: const [
BottomNavigationBarItem(
icon:Icon(Icons.business),
label: "Home"
),
BottomNavigationBarItem(
icon:Icon(Icons.business),
label: "Home"
),
BottomNavigationBarItem(
icon:Icon(Icons.business),
label: "Home"
)
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
);


 WidgetsBindingObserver

 class _LifecycleWatcherState extends State<LifecycleWatcher> with WidgetsBindingObserver {

  AppLifecycleState _lastLifecycleState;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    setState(() {
      _lastLifecycleState = state;
    });
  }

  @override
  Widget build(BuildContext context) {
    if (_lastLifecycleState == null)
      return Text('This widget has not observed any lifecycle changes.', textDirection: TextDirection.ltr);

    return Text('The most recent lifecycle state this widget observed was: $_lastLifecycleState.',
        textDirection: TextDirection.ltr);
  }
}
  



https://medium.com/flutter-korea/row-column-widgets-8c1ff09a6219


https://bsscco.github.io/posts/flutter-introduction-to-animations/