Skip to content

Instantly share code, notes, and snippets.

@jiahaog
Created April 16, 2024 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiahaog/81f30a17ac085470c428e7bd04e29ac2 to your computer and use it in GitHub Desktop.
Save jiahaog/81f30a17ac085470c428e7bd04e29ac2 to your computer and use it in GitHub Desktop.
ListView vs SingleChildScrollView
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