Flutter Tutorials

Flutter app development tutorials


flutter – ListTile separator

main.dart


import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      theme: ThemeData(primarySwatch: Colors.green),
      home: Scaffold(
          appBar: AppBar(
              title: const Text("Flutter - ListTile Separator")
          ),
          body: bodyContent()
      ),
    ),
  );
}

bodyContent(){
  return Center(
      child: ListView.separated(
          itemCount: 50,
          padding: const EdgeInsets.all(8),
          itemBuilder: (context,index){
            return ListTile(
                title: Text("${index+1}. I am title"),
                subtitle: const Text("I am subtitle"),
                trailing: const Icon(Icons.grading),
                contentPadding: const EdgeInsets.symmetric(
                    horizontal: 24, vertical: 12
                ),
                tileColor: index % 2 ==0 ?
                Colors.green.shade50 : Colors.green.shade100
            );
          },
          separatorBuilder: (context, index) {
            return Divider(
              color: Colors.green.shade300,
              height: 1.2,
              thickness: 1.2
            );
          }
      )
  );
}

More flutter tutorials



About Me

Flutter Developer

Design a site like this with WordPress.com
Get started