Last active
August 27, 2022 18:19
-
-
Save iapicca/eadcecbe0065313e2efea11495052300 to your computer and use it in GitHub Desktop.
issue_109983 (b)
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: LayoutBuilder( | |
| builder: (context, constraints) => ConstrainedBox( | |
| constraints: constraints, | |
| child: SingleChildScrollView( | |
| child: ConstrainedBox( | |
| constraints: constraints, | |
| child: Column( | |
| children: [ | |
| const Text('header'), | |
| const Expanded( | |
| child: ColoredBox( | |
| color: Colors.green, | |
| child: Text('body'), | |
| ), | |
| ), | |
| const Text('footer'), | |
| SizedBox( | |
| height: 200, | |
| child: 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) => Text( | |
| strings[index], | |
| ), | |
| ), | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment