Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views2 pages

Main Page

The document is a Flutter application code for a Todo List app, featuring a main page with a list of tasks. Users can add new tasks or edit existing ones through a dialog interface. The app utilizes a stateful widget to manage the list of tasks and user input via a text controller.

Uploaded by

Muhammad Ahyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Main Page

The document is a Flutter application code for a Todo List app, featuring a main page with a list of tasks. Users can add new tasks or edit existing ones through a dialog interface. The app utilizes a stateful widget to manage the list of tasks and user input via a text controller.

Uploaded by

Muhammad Ahyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import 'package:flutter/material.

dart';
import 'package:myapp/form_dialog.dart';

class MainPage extends StatefulWidget {


const MainPage({super.key});

@override
State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {


List<String> todoData=['Belajar Flutter'];
TextEditingController controller=TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color.fromARGB(255, 207, 74, 41),
title: Text(
'Todo List App',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
textAlign: TextAlign.center,
),
),
body: ListView.builder(
itemCount: todoData.length,
itemBuilder: (context,index) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
todoData[index],
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
GestureDetector(
onTap: (){
controller.text=todoData[index];
showDialog(
context: context,
builder: (context)=>FormDialog(
isEdit: true,
onPress: (){
setState((){
todoData[index]=controller.text;
});
controller.clear();
Navigator.pop(context);
},
controller: controller,
),
);
},
child: Icon(Icons.edit),
)],
),
),
Divider(height: 1),
],
);
}
),
floatingActionButton: ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (context)=>FormDialog(
controller: controller,
onPress: (){
setState((){
todoData.add(controller.text);
});
controller.clear();
Navigator.pop(context);
},
),
);
},
child: Icon(Icons.add),
),
);
}
}

You might also like