Reputation: 51
I am trying to render a listview and divider in a column and have used a container to restrict the height.The text of the List Tiles is shown only within the Container however the listtile colour is shown outside the container. I want this layout but for the colour to be only shown within the container as well.
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(10),
),
height: MediaQuery.of(context).size.height * 0.5,
width: MediaQuery.of(context).size.width * 0.8,
child: ListView.builder(
itemCount: 20,
itemBuilder: (ctx, index) => Column(
children: [
ListTile(
tileColor: Colors.red,
leading: Text("Test"),
),
Divider()
],
),
),
)
Upvotes: 2
Views: 1125
Reputation: 11
Simply wrap the ListTile with the Card to avoid overflow; similar to the example in the docs.
Card(
child: ListTile(//...)
//...
)
Upvotes: 1
Reputation: 63839
updated
import 'package:flutter/material.dart';
class SEList extends StatelessWidget {
const SEList({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Icon(
Icons.menu,
color: Colors.white,
),
title: Text("User Profile"),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: LayoutBuilder(
builder: (context, constraints) => Column(
children: [
Container(
child: Center(
child: Column(
children: [
Text("Name"),
Text("Name"),
Text("Name"),
Text("Name"),
Container(
height: 70,
child: Text(
"Job",
style: TextStyle(
fontSize: 24,
),
),
)
],
),
),
),
SizedBox(
/// 70% of screen for listView
height: constraints.maxHeight * .65,
child: ListView.separated(
itemBuilder: (context, index) => Container(
child: Text("Text $index"),
height: 70,
color: Colors.redAccent,
),
separatorBuilder: (context, index) => Divider(
thickness: 1.2,
),
itemCount: 30,
),
)
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(
Icons.upload_file,
),
),
);
}
}
Upvotes: 0