Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroo11d authored Oct 14, 2021
1 parent d943694 commit 35cb006
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Task2/checkBox.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';

class Check extends StatelessWidget {
final bool isActive;

const Check({Key? key, required this.isActive}) : super(key: key);

@override
Widget build(BuildContext context) {
if (isActive) {
return Container(
width: 30,
height: 30,
decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.pink),
child: Icon(
Icons.check,
size: 20,
color: Colors.white,
),
);
} else {
return Container(
width: 30,
height: 30,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
border: Border.all(
color: Colors.grey,
width: 3,
)),
child: Icon(
Icons.check,
size: 20,
color: Colors.white,
),
);
}
}
}
143 changes: 143 additions & 0 deletions Task2/home.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:todo2/home.dart';
import 'package:todo2/todo.dart';

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
Map<String, dynamic> todo = {};
TextEditingController _controller = new TextEditingController();

@override
void initState() {
_loadData();
}

_loadData() async {
SharedPreferences storage = await SharedPreferences.getInstance();

if (storage.getString('todo') != null) {
var storage2 = storage;
var string = storage2.getString('todo');
todo = jsonDecode(string!);
}
}

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text('Todo App'),
backgroundColor: Colors.pink,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 30,
),
Expanded(
child: ListView.builder(
itemCount: todo.length,
itemBuilder: (context, data) {
return Dismissible(
key: Key('item' + data.toString()),
onDismissed: (direction) {
todo.remove(todo.keys.elementAt(data));
_save();
},
child: InkWell(
onTap: () {
setState(() {
todo[todo.keys.elementAt(data)] =
!todo[todo.keys.elementAt(data)];
});
_save();
},
child: TodoItem(
name: todo.keys.elementAt(data),
isActive: todo.values.elementAt(data)),
),
);
},
),
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(
backgroundColor: Colors.pink,
),
body: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _controller,
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: InputDecoration(
hintText: 'Write....',
),
),
),
//actions:
FlatButton(
child: Text(
'save',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold),
),
onPressed: () {
Navigator.pop(context);
_addTodo();
},
),
//child: child)
],
),
))));
},
child: Icon(Icons.add),
backgroundColor: Colors.pink,
),
),
),
);
}

_addTodo() async {
setState(() {});
SharedPreferences storage = await SharedPreferences.getInstance();

if (_controller.text.length > 0) {
setState(() {
todo.putIfAbsent(_controller.text, () => false);
storage.setString('todo', jsonEncode(todo));
});
}
setState(() {});
}

_save() async {
SharedPreferences storage = await SharedPreferences.getInstance();

storage.setString('todo', jsonEncode(todo));
}
}
69 changes: 69 additions & 0 deletions Task2/todo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import 'package:todo2/checkBox.dart';

class TodoItem extends StatefulWidget {
final String name;
final bool isActive;

const TodoItem({Key? key, required this.name, required this.isActive})
: super(key: key);

@override
_TodoItemState createState() => _TodoItemState();
}

class _TodoItemState extends State<TodoItem> {
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 50),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.of(context).size.width / 100 * 50,
child: Text(
widget.name,
style: TextStyle(
fontSize: 17,
color: Colors.black,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: true,
),
),
/////////////////////////////////
Row(
children: [
Text(
DateFormat('d ').format(DateTime.now()),
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.black45),
),
Text(
DateFormat('MMM ').format(DateTime.now()).toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black45),
),
Text(
DateFormat('y').format(DateTime.now()),
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black45),
),
],
),

/////////////////////////////////
Check(
isActive: widget.isActive,
)
],
),
);
}
}

0 comments on commit 35cb006

Please sign in to comment.