I have the following code
import 'package:flutter/material.dart';
class AddListingScreen extends StatefulWidget {
const AddListingScreen({super.key});
@override
State<AddListingScreen> createState() => _AddListingScreenState();
}
class _AddListingScreenState extends State<AddListingScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Demo')),
body: SingleChildScrollView(
padding: const EdgeInsets.all(Dimens.spacingMedium),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text('Search todo'),
ListView.separated(
itemBuilder: (context, index) => Text(demo[index]),
separatorBuilder: (context, index) =>
const SizedBox(
height: Dimens.spacingSmall,
),
itemCount: demo.length),
// I plan to add more items here, and might have another ListView as well afterward
// Idea is to have only 1 single scroll for the entire page!
],
)),
);
}
}
final List<String> demo = ['a', 'b', 'c'];
If I comment out the ListView
the page renders fine.
I tried
- Wrapping ListView with
Expanded
and did not work - Using ConstrainBox on the Column, did not work
- ALMOST WORKS
Adding
shrinkWrap: true,
to the ListView.separated works partially.
The render error is fixed, there is only one scrollbar but I can’t scroll until the bottom!
Any ideas ?
2
Answers
SingleChildScrollView and ListView both trying to get infinite height(size) which is causing the layout issue. I will suggest using CustomScrollView in this case.
in the second listView:
NeverScrollableScrollPhysics()
`