Skip to content

Instantly share code, notes, and snippets.

@matifdeveloper
Created January 23, 2024 05:39
Show Gist options
  • Save matifdeveloper/6d7ab223955d80039862cd24fa9d7fc3 to your computer and use it in GitHub Desktop.
Save matifdeveloper/6d7ab223955d80039862cd24fa9d7fc3 to your computer and use it in GitHub Desktop.
Nested ListView.builder in Flutter

Nested ListView.builder in Flutter

Created with <3 with dartpad.dev.

import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Nested ListView.builder Example'),
),
body: MyNestedListView(),
),
);
}
}
class MyNestedListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: 5, // Number of outer list items
itemBuilder: (context, index) {
return Card(
margin: const EdgeInsets.all(8.0),
child: Column(
children: [
ListTile(
title: Text('Outer List Item $index'),
),
// Inner ListView.builder
SizedBox(
height: 150.0, // Set the height of the inner list
child: ListView.builder(
scrollDirection: Axis.horizontal, // Set the direction if needed
itemCount: 10, // Number of inner list items
itemBuilder: (context, innerIndex) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.blue,
width: 100.0,
child: Center(
child: Text('Inner List Item $innerIndex', textAlign: TextAlign.center),
),
),
);
},
),
),
],
),
);
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment