Created
August 27, 2022 17:26
-
-
Save iapicca/d8a8cb24e191ee7b164529c332235c44 to your computer and use it in GitHub Desktop.
issue_109983
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() => runApp(const MaterialApp(home: MyHomePage())); | |
| class MyHomePage extends StatefulWidget { | |
| const MyHomePage({super.key}); | |
| @override | |
| State<MyHomePage> createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| late final ValueNotifier<List<String>> _notifier; | |
| @override | |
| void initState() { | |
| _notifier = ValueNotifier([]); | |
| super.initState(); | |
| } | |
| @override | |
| void dispose() { | |
| _notifier.dispose(); | |
| super.dispose(); | |
| } | |
| void _add() => _notifier.value = [ | |
| '${_notifier.value.length}', | |
| ..._notifier.value, | |
| ]; | |
| @override | |
| Widget build(context) => Scaffold( | |
| appBar: AppBar(title: const Text('AppBar')), | |
| body: MyListView(notifier: _notifier), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: _add, | |
| child: const Icon(Icons.add), | |
| ), | |
| ); | |
| } | |
| class MyListView extends StatelessWidget { | |
| final ValueNotifier<List<String>> notifier; | |
| const MyListView({ | |
| required this.notifier, | |
| super.key, | |
| }); | |
| @override | |
| Widget build(context) => ValueListenableBuilder<List<String>>( | |
| valueListenable: notifier, | |
| builder: (context, strings, child) => ListView.builder( | |
| reverse: true, | |
| itemCount: strings.length, | |
| itemBuilder: (context, index) => ListTile( | |
| title: Text( | |
| strings[index], | |
| ), | |
| ), | |
| ), | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment