Created
April 16, 2024 08:38
-
-
Save jiahaog/81f30a17ac085470c428e7bd04e29ac2 to your computer and use it in GitHub Desktop.
ListView vs SingleChildScrollView
This file contains 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 MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
static const n = 10; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Column( | |
children: [ | |
Text('Listview(reverse = true)'), | |
Container( | |
height: 200, | |
child: ListView.builder( | |
itemCount: n, | |
itemBuilder: (context, i) => Text('ListView.builder $i'), | |
reverse: true, | |
), | |
), | |
Text('SCSV(reverse = true)'), | |
Container( | |
height: 200, | |
child: SingleChildScrollView( | |
child: Column( | |
children: [for (var i = 0; i < n; i += 1) Text('SCSV $i')], | |
), | |
reverse: true, | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment