Skip to content

Instantly share code, notes, and snippets.

@PiN73
Created May 26, 2019 16:29
Show Gist options
  • Save PiN73/ab160fdc8a9d726c92af8d975a53c0bc to your computer and use it in GitHub Desktop.
Save PiN73/ab160fdc8a9d726c92af8d975a53c0bc to your computer and use it in GitHub Desktop.
Flutter - ListView saving items data
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyPage(),
);
}
}
class MyPage extends StatefulWidget {
@override
_MyPageState createState() => _MyPageState();
}
class _MyPageState extends State<MyPage> {
int _count = 1;
void _addItem() {
setState(() {
_count += 1;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemBuilder: (ctx, i) => TextField(),
itemCount: _count,
),
floatingActionButton: FloatingActionButton(
onPressed: _addItem,
child: Icon(Icons.add),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment