You are on page 1of 9

Assignment no 01

Subject name : Mobile App Development

Submitted to : Ma’am Sumaira

Submitted By

Name Roll Number

Tabish 41

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/assignment1.dart'; void main()
{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