0% found this document useful (0 votes)
8 views

App Assignment 2

The document describes a mobile app development assignment submitted by Tabish Akhtar to Mam Sumaira. The assignment involves building a todo list app in Flutter with a homepage that allows adding, editing, and deleting todo tasks for 6 days. The app stores the tasks in a Contact class and displays them in a listview.

Uploaded by

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

App Assignment 2

The document describes a mobile app development assignment submitted by Tabish Akhtar to Mam Sumaira. The assignment involves building a todo list app in Flutter with a homepage that allows adding, editing, and deleting todo tasks for 6 days. The app stores the tasks in a Contact class and displays them in a listview.

Uploaded by

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

Assignment no : 02

Subject: Mobile App Development

Session: 2020-2024

Semester: BS(CS)6th

Submitted to: Mam Sumaira

Submitted by;
Name Roll no
Tabish Akhtar 41

Submission date: 19-sep-2023

University of Poonch Rawalakot

Department of CS& IT
main.dart

import 'package:ass2/screens/home_page.dart'; import


'package:flutter/material.dart';

void main()
{ runApp(const
MyApp());
}

class MyApp extends StatelessWidget {


const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) { return
MaterialApp(
title: 'Contacts List',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.purple,
),
home: const HomePage(),
);
}
}
home_page.dart

import 'package:ass2/screens/contact.dart';
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget { const


HomePage({Key? key}) : super(key: key);

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {


TextEditingController day1taskController = TextEditingController();
TextEditingController day2taskController= TextEditingController();
TextEditingController day3taskController= TextEditingController();
TextEditingController day4taskController= TextEditingController();
TextEditingController day5taskController= TextEditingController();
TextEditingController day6taskController= TextEditingController();
List<Contact> contacts = List.empty(growable: true);
int selectedIndex = -1;

@override
Widget build(BuildContext context) {
return
Scaffold( appBar:
AppBar( centerTitle:
true,
title: const Text('Todo List'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column( children: [
const SizedBox(height: 10),
TextField( controller:
day1taskController , decoration:
const InputDecoration(
hintText: 'Day1 task',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
))),
),
const SizedBox(height: 10),
TextField(
controller: day2taskController,
decoration: const InputDecoration(
hintText: 'Day2 task', border:
OutlineInputBorder( borderRadi
us: BorderRadius.all(
Radius.circular(10),
))),
),
const SizedBox(height: 10),
TextField(
controller: day3taskController,
decoration: const InputDecoration(
hintText: 'Day3 task', border:
OutlineInputBorder( borderRadi
us: BorderRadius.all(
Radius.circular(10),
))),
),
const SizedBox(height: 10),
TextField( controller:
day4taskController, decoration:
const InputDecoration(
hintText: 'Day4 task',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
))),
),
const SizedBox(height: 10),
TextField(
controller: day5taskController,
keyboardType: TextInputType.number,
maxLength: 10,
decoration: const InputDecoration(
hintText: 'Day5 task',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
))),
),
const SizedBox(height: 10),
TextField( controller:
day6taskController, decoration:
const InputDecoration(
hintText: 'Day6 task',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
))),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: () {
//
String day1task = day1taskController.text.trim();
String day2task = day2taskController.text.trim();
String day3task = day3taskController.text.trim();
String day4task = day4taskController.text.trim();
String day5task = day5taskController.text.trim();
String day6task = day6taskController.text.trim(); if
(day1task.isNotEmpty && day2task.isNotEmpty &&day3task.isNotEmpty
&&day4task.isNotEmpty &&day5task.isNotEmpty && day6task.isNotEmpty )
{ setState(() { day1taskController.text = '';
day2taskController.text = ''; day3taskController.text = '';
day4taskController.text = ''; day5taskController.text = '';
day6taskController.text = '';

contacts.add(Contact(day1task:day1task,day2task:day2task,day3task:day3task,day4task:day4task,day5task:day5tas
k ,day6task:day6task ));
});
}
//
},
child: const Text('Save')),
ElevatedButton(
onPressed: () {
//
String day1task = day1taskController.text.trim();
String day2task = day2taskController.text.trim();
String day3task = day3taskController.text.trim();
String day4task = day4taskController.text.trim();
String day5task = day5taskController.text.trim();
String day6task = day6taskController.text.trim();
if ( day1task.isNotEmpty && day2task.isNotEmpty &&day3task.isNotEmpty
&&day4task.isNotEmpty &&day5task .isNotEmpty && day6task.isNotEmpty)
{ setState(() { day1taskController.text = '';
day2taskController.text = ''; day3taskController.text = '';
day4taskController.text = ''; day5taskController.text = '';
day6taskController.text = '';

contacts[selectedIndex].day1task =day1task ;
contacts[selectedIndex].day2task = day2task;
contacts[selectedIndex].day3task =day3task ;
contacts[selectedIndex].day4task = day4task;
contacts[selectedIndex].day5task =day5task ;
contacts[selectedIndex].day6task = day6task;
selectedIndex = -1;
});
}
//
},
child: const Text('Update')),
],
),
const SizedBox(height: 10),
contacts.isEmpty ? const
Text(
'No task yet..',
style: TextStyle(fontSize: 22),
)
:
Expanded( child:
ListView.builder(
itemCount: contacts.length,
itemBuilder: (context, index) => getRow(index),
),
)
],
),
),
);
}

Widget getRow(int index) {


return Card( child:
ListTile( leading:
CircleAvatar( backgr
oundColor:
index % 2 == 0 ? Colors.deepPurpleAccent : Colors.purple,
foregroundColor: Colors.white, child: Text(
contacts[index].day1task[0],
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
title: Column(
crossAxisAlignment:
CrossAxisAlignment.start, children: [
Text(
contacts[index].day1task,
style: const TextStyle(fontWeight: FontWeight.bold),
),
Text(contacts[index].day2task),
Text(contacts[index].day3task),
Text(contacts[index].day4task),
Text(contacts[index].day5task),
Text(contacts[index].day6task),

],
),
trailing: SizedBox(
width: 70,
child:
Row( children:
[ InkWell(
onTap: () {
//
day1taskController.text = contacts[index].day1task;
day2taskController.text = contacts[index].day2task;
day3taskController.text = contacts[index].day3task;
day4taskController.text = contacts[index].day4task;
day5taskController.text = contacts[index].day5task;
day6taskController.text = contacts[index].day6task;
setState(() { selectedIndex = index;
});
//
},
child: const Icon(Icons.edit)),
InkWell( onTap: (() {
//
setState(() {
contacts.removeAt(index);
});
//
}),
child: const Icon(Icons.delete)),
],
),
),
),
);
}
}

Contact.dart
class Contact
{ String day1task;
String day2task;
String day3task;
String day4task;
String day5task;
String day6task;

Contact({required this.day1task, required this.day2task,required this.day3task,required this.day4task,required


this.day5task,required this.day6task}); }
Output
After update record

You might also like