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

Hasnat App

The document is an assignment submission for a mobile app development class. It includes the student's name, roll number, class details, and date. It also includes code for a todo list mobile application built with Flutter. The code includes creating a list of todo items, adding new items via a text field, marking items as complete with checkboxes, and deleting items. It also counts the number of items added and deleted.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Hasnat App

The document is an assignment submission for a mobile app development class. It includes the student's name, roll number, class details, and date. It also includes code for a todo list mobile application built with Flutter. The code includes creating a list of todo items, adding new items via a text field, marking items as complete with checkboxes, and deleting items. It also counts the number of items added and deleted.

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 PDF, TXT or read online on Scribd
You are on page 1/ 9

Assignment no 01

Subject name : Mobile App Development

Submitted to : Ma’am Sumaira

Submitted By

Name Roll Number

Hasnat Kamal 65

Class name : BSCS 6th

Session : 2020-2024

Date : 28-08-2023

University of poonch Rawlakot


Given formate :

SOLUTION :
Code :
#main page
import
'package:flutter/
material.dart';
import
'package:assignment/screens/a
ssignment1.dart'; voidmain()
{ runApp( MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the
root of your application.
@override
Widget build(BuildContext context)
{ return MaterialApp(
title:
'Flutter
Demo', theme:ThemeData(
primarySwatch: Colors.lightGreen,
),
home: MyHomePage1('') ,
);
}
}
#assignment.dart
import 'package:flutter/material.dart';

void main() {
runApp(MaterialApp(
theme: ThemeData(primaryColor: Colors.deepPurple),
home: MyHomePage1('Todo Manager'),
));
}
class MyHomePage1 extends StatefulWidget {
final String title;
MyHomePage1(this.title);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage1> {
List<TodoItem> _todoItems = [
TodoItem(title: 'selection of things', isSelected: false),
TodoItem(title: 'destroy useless things', isSelected: false),
];

TextEditingController _textFieldController = TextEditingController(); //


Add this line

int tasksAdded = 0; int


checkboxesDeleted = 0;

@override
void dispose() {
_textFieldController.dispose(); // Dispose the controller
super.dispose();
}

@override
Widget build(BuildContext context)
{ return Scaffold( appBar:
AppBar(
title: Text('Todo Manager'),
),
body: Container(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 16.0),
Expanded(
child: SingleChildScrollView(
child: Column(
children: _buildTodoList(),
),
),
),
SizedBox(height: 16.0),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0), // Rounded border
color: Colors.lightGreen,
),
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextField(
controller: _textFieldController, // Set the controller
style: TextStyle(fontSize: 20.0, fontWeight:FontWeight.bold),
decoration: InputDecoration( labelText:
'Add a new task',
border: InputBorder.none, // Hide the default border
),
onChanged: (text) {
setState(() {
// No need to store text in _newTodoText anymore
});
},
),
),
),
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.red, // Change the color to red
),
child: IconButton(
onPressed: () {
setState(() {
final newTask = _textFieldController.text;
if (newTask.isNotEmpty) {
_todoItems.add(
TodoItem(title: newTask, isSelected: false));
_textFieldController.clear(); // Clear the text field
tasksAdded++;
}
});
}, icon: Icon(
Icons.add, color:
Colors.white,
),
),
),
],
),
),
SizedBox(height: 16.0),
Text('Tasks Added: $tasksAdded'),
Text('Checkboxes Deleted: $checkboxesDeleted'),
],
),
),
);
}

List<Widget> _buildTodoList() {
List<Widget> todoWidgets = [];
for (int index = 0; index < _todoItems.length; index++) {
final item = _todoItems[index];
todoWidgets.add(Card(
elevation: 4.0,
margin: EdgeInsets.symmetric(vertical:
8.0), child: ListTile( leading:
Checkbox( value: item.isSelected,
onChanged: (bool? value) {
setState(() {
item.isSelected = value!;
});
}, ),
title: Text(
item.title,
style: TextStyle(
decoration: item.isSelected ? TextDecoration.lineThrough : null,
),
),
trailing:
GestureDetector( onTap:
() { setState(() {
_todoItems.removeAt(index);
checkboxesDeleted++;
});
},
child: Icon(Icons.delete, color: Colors.red), // Change icon color to red
),
),
));
}
return todoWidgets;
}
}
class TodoItem {
String title;
bool isSelected;

TodoItem({required this.title, required this.isSelected});


}
Output:

Full :

Appbar :

Checkboxes and delete(function)icon:


Add text(checkboxes) field:

Count function for added and deleted checkboxes::

THE END

You might also like