flutter listview builder
List<String> litems = ["1","2","Third","4"];
body: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
return new Text(litems[index]);
}
)
flutter listview builder
List<String> litems = ["1","2","Third","4"];
body: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
return new Text(litems[index]);
}
)
how to update listview in flutter
// Assuming you've extended the StatefulWidget, you must call setState
// everytime you change the state. Ex:
setState(() { propList.add('text'); });
// Quick Example
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) => MaterialApp(home: MyList());
}
class MyList extends StatefulWidget {
@override
_MyListState createState() => _MyListState();
}
class _MyListState extends State<MyList> {
List<String> propList = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My List'),
),
body: ListView.builder(
itemCount: propList.length,
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemBuilder: (context,index)=> Text(propList[index]),
),
floatingActionButton: FloatingActionButton(
onPressed: () => setState(() => propList.add('text')),
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us