Flutter listview background color

Flutter ListView Background Color

To set the background color of a ListView in Flutter, you can use the `Container` widget as a parent of the ListView and set the `color` property of the Container to the desired background color. Here’s an example:


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: Text('ListView with Background Color'),
        ),
        body: Container(
          color: Colors.blueGrey, // Set the background color here
          child: ListView.builder(
            itemCount: 10,
            itemBuilder: (context, index) {
              return ListTile(
                title: Text('Item $index'),
              );
            },
          ),
        ),
      ),
    );
  }
}
    

In the above example, the `Container` widget wraps the `ListView.builder` widget and sets the `color` property to `Colors.blueGrey`. This sets the background color of the ListView to blue-grey.

You can replace `Colors.blueGrey` with any other color from the `Colors` class, or you can define a custom color using the `Color` class.

Leave a comment