Ticker

6/recent/ticker-posts

How to customize item's list with ListTile in ListView in flutter

The ListTile widget is one of widget that used in ListView widget. 
The ListTile widget provide: 
  • title : display on the top 
  • subtitle: display under title
  • actions: created the click action at end of row
main.dart

import 'package:flutter/material.dart';
import 'dart:core';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter ListView'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

List<int> lists = [];

@override
initState(){
super.initState();
for(int i = 0 ; i < 50; i++) {
lists.add ( i + 1);
}
}

Future<Null> onRefresh() async{
await Future.delayed(Duration(seconds: 3)).then((_) => {
setState((){
lists.insert(0, 100);
})
});
}

@override
Widget build(BuildContext context) {

return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(
itemCount: lists.length,
itemBuilder: (context, index){
return ListTile(
onTap: (){showSnackBar(context);},
title: Text('Title ${lists[index]} '),
subtitle: Text('This is subtitle #${lists[index]}')
);
})
)
);
}

void showSnackBar(BuildContext context){
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text("Hello, this is simple SnackBar"),
action: SnackBarAction(label: 'OK', onPressed: (){},),
)
);
}
}


Below videos, It will show you how to implement step by step of ListView Items. Please watch and check. 

Post a Comment

0 Comments