Created
May 26, 2019 16:29
-
-
Save PiN73/ab160fdc8a9d726c92af8d975a53c0bc to your computer and use it in GitHub Desktop.
Flutter - ListView saving items data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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