Untitled
unknown
plain_text
4 years ago
2.2 kB
16
Indexable
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Ignite Todo',
theme: ThemeData(
primarySwatch: Colors.pink,
),
home: const MyTodoPage(),
);
}
}
class MyTodoPage extends StatefulWidget {
const MyTodoPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _MyTodoPageState();
}
class _MyTodoPageState extends State<MyTodoPage> {
final items = [for (var i = 0; i < 100; i++) 'item $i'];
final _inputTextFieldController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
"todo",
style: TextStyle(color: Colors.black),
),
actions: [
TextButton(
child: const Text(
'help',
style: TextStyle(color: Colors.black),
),
onPressed: () {},
),
],
),
body: ListView(
children: [
ListTile(
title: TextField(
decoration: const InputDecoration(hintText: 'Add new item...'),
controller: _inputTextFieldController,
),
trailing: IconButton(
icon: const Icon(Icons.add),
onPressed: () {
final text = _inputTextFieldController.text;
if (text.isEmpty) return;
setState(() {
items.insert(0, text);
});
},
),
),
for (var i = 0; i < items.length; i++)
ListTile(
title: Text(items[i]),
trailing: IconButton(
icon: const Icon(Icons.remove),
onPressed: () {
setState(() {
items.removeAt(i);
});
},
),
),
],
),
);
}
}
Editor is loading...