Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- navigator
- HTTP
- flutter
- Cached Image
- Networking
- WillPopScope
- sqlite
- Hello World
- 반석천
- node.js
- Flutter 앱 배포
- ListView.builder
- Load Image
- listview
- InkWell
- Scaffold
- Row Widget
- MainAxisAlignment
- Image.network
- Snackbar
- Flutter Example
- Flutter 강좌
- ListTile
- Flutter 예제
- Column Widget
- AppBar
- Row
- FutureBuilder
- Flutter Tutorial
- CrossAxisAlignment
Archives
- Today
- Total
꿈꾸는 시스템 디자이너
Flutter Example - ListView | Handle Items | Change items 본문
Tutorial/Flutter with App
Flutter Example - ListView | Handle Items | Change items
독행소년 2020. 3. 24. 11:30
import 'package:flutter/material.dart';
ListViewHandelItem2State pageState;
class ListViewHandelItem2 extends StatefulWidget {
@override
ListViewHandelItem2State createState() {
pageState = ListViewHandelItem2State();
return pageState;
}
}
class ListViewHandelItem2State extends State<ListViewHandelItem2> {
List<String> items = List<String>.generate(7, (index) {
return "Item - $index";
});
TextEditingController insertCon = TextEditingController(
text: "good",
);
TextEditingController changeCon = TextEditingController();
int selectedIndex;
@override
void dispose() {
insertCon.dispose();
changeCon.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("ListView Handle Items2")),
body: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
padding: const EdgeInsets.all(10),
height: 70,
alignment: Alignment(0, 0),
color: Colors.orange,
child: Text(
"To remove an item, swipe the tile to the right or tap the trash icon.",
style: TextStyle(color: Colors.white),
),
),
),
Expanded(
child: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
return Dismissible(
key: Key(item),
direction: DismissDirection.startToEnd,
child: InkWell(
child: ListTile(
title: Text(item),
trailing: IconButton(
icon: Icon(Icons.delete_forever),
onPressed: () {
setState(() {
items.removeAt(index);
});
},
),
),
onTap: () {
selectedIndex = index;
changeCon.text = items[index];
},
),
onDismissed: (direction) {
setState(() {
items.removeAt(index);
});
},
);
},
),
),
Divider(
color: Colors.grey,
height: 5,
indent: 10,
endIndent: 10,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Row(
children: <Widget>[
Text("Change Item:"),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: TextField(
controller: changeCon,
onSubmitted: (text) {
_changeItem();
},
),
),
),
RaisedButton(
child: Text("Change"),
onPressed: () {
_changeItem();
},
)
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Row(
children: <Widget>[
Text("Inser Item:"),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: TextField(
controller: insertCon,
onSubmitted: (text) {
setState(() {
if (insertCon.text != "") {
items.add(insertCon.text);
}
});
insertCon.clear();
},
),
),
),
RaisedButton(
child: Text("Insert"),
onPressed: () {
setState(() {
if (insertCon.text != "") {
items.add(insertCon.text);
}
});
insertCon.clear();
},
)
],
),
),
],
),
);
}
void _changeItem() {
if (selectedIndex == null || changeCon.text.isEmpty) {
return;
}
print("selectedIndex: $selectedIndex, changedText: ${changeCon.text}");
setState(() {
items[selectedIndex] = changeCon.text;
});
selectedIndex = null;
changeCon.text = "";
}
}
▶ Go to Table of Contents | 강의 목차로 이동
※ This example is also available in the Flutter Code Examples app. | 본 예제는 Flutter Code Examples 앱에서도 제공됩니다.
'Tutorial > Flutter with App' 카테고리의 다른 글
Flutter Example - TCP Socket Client (9) | 2020.04.14 |
---|---|
Flutter Example - TCP Socket Server (0) | 2020.04.14 |
Flutter Example - How to set the volume | volume plugin (2) | 2020.03.23 |
Flutter Example - How to add Admob Ad in Flutter App | firebase_admob plugin (0) | 2019.10.31 |
Flutter Example - Http Request | Get method | http plugin (0) | 2019.10.23 |
Comments