Skip to content

Commit

Permalink
added swipe options (complete and delete). updated UI to look a bit m…
Browse files Browse the repository at this point in the history
…ore like Figma designs
  • Loading branch information
armintalaie committed Dec 1, 2021
1 parent 98808b4 commit c44a083
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 106 deletions.
152 changes: 106 additions & 46 deletions frontend/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:src/task.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:src/widgets/interactive_task.dart';

void main() {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -16,10 +17,8 @@ class TaskScheduler extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Tasks',
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: const MyHomePage(title: 'My Tasks'),
theme: ThemeData(primarySwatch: Colors.pink),
home: const MyHomePage(title: 'Tasks'),
);
}
}
Expand All @@ -36,6 +35,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
bool _initialized = false;
bool _error = false;
bool _toAdd = true;

// Define an async function to initialize FlutterFire
void initializeFlutterFire() async {
Expand All @@ -62,65 +62,125 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
FirebaseFirestore firestore = FirebaseFirestore.instance;
CollectionReference tasks = firestore.collection('tasks');
CollectionReference tasks = firestore.collection('testingTaskCollection');

void addTask() {
setState(() {
_toAdd = !_toAdd;
});
}

if (!_initialized) {
return Scaffold(
appBar: AppBar(
title: const Text("NOT CONNECTED TO FIREBASE"),
backgroundColor: Color(0xff885566),
),
);
}

return Scaffold(
appBar: AppBar(
elevation: 0,
bottom: PreferredSize(
child: Container(
color: Colors.grey,
height: 0.5,
),
preferredSize: const Size.fromHeight(7.0)),

titleSpacing: 10,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Column(children: [
Container(
child: const Align(
alignment: Alignment.centerLeft,
child: Text(
"Inbox",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
title: const Align(
alignment: Alignment.centerLeft,
child: Text(
"Inbox",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 24, color: Colors.black),
),
padding: const EdgeInsets.all(12.0),
),
FutureBuilder(
future: tasks.get(),
builder: (_, AsyncSnapshot snapshot) {
return snapshot.hasData
? Container(
height: MediaQuery.of(context).size.height * 0.6,
child: ListView.builder(
padding: const EdgeInsets.all(4.0),
itemCount: snapshot.data.docs.length,
reverse: false,
itemBuilder: (context, index) {
DocumentSnapshot ds = snapshot.data.docs[index];
return Task(
title: ds.data()["title"].toString(),
description:
ds.data()["description"].toString(),
ds: ds);
}))
: const Text("NOT CONNECTED TO DATABASE");
}),
FloatingActionButton(
onPressed: () {},
child: const Icon(
Icons.add,
color: Colors.white,
size: 44.0,
semanticLabel: 'Text to announce in accessibility modes',
backgroundColor: Colors.white,
),
body: Stack(
children: [
Container(
margin: const EdgeInsets.only(top: 20),
child: Column(children: [
FutureBuilder(
future: tasks.get(),
builder: (_, AsyncSnapshot snapshot) {
return snapshot.hasData
? Column(children: [
Container(
height:
MediaQuery.of(context).size.height * 0.4,
child: ListView.builder(
padding: const EdgeInsets.all(4.0),
itemCount: snapshot.data.docs.length,
reverse: false,
itemBuilder: (context, index) {
DocumentSnapshot ds =
snapshot.data.docs[index];
return InteractiveTask(ds: ds);
})),
])
: const Text("NOT CONNECTED TO DATABASE");
}),
]),
),
),
]),

// This trailing comma makes auto-formatting nicer for build methods.
if (_toAdd)
Positioned.fill(
child: Align(
alignment: Alignment.topCenter,
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Task(title: "title", description: "description"),
color: Color.fromRGBO(173, 173, 173, 0.9),
padding: EdgeInsets.all(5),
))),
// if (_toAdd)
// Positioned(
// top: 30,
// child: Container(
// height: MediaQuery.of(context).size.height * 0.2,
// width: MediaQuery.of(context).size.width,
// color: Color(0xD4C3C3),
// padding: EdgeInsets.all(10),
// child: Task(title: "title", description: "descrription"),
// ),
// ),
// Can be replaced with a custom widget to add task
// Positioned.fill(
// child: Align(
// alignment: Alignment.centerRight,
// child: Task(title: "title", description: "description"),
// ),
// ),
Positioned(
right: 10,
bottom: 10,
child: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
addTask();
},
))
],
),
);
}

Widget _buildPopupDialog(BuildContext context) {
return new AlertDialog(
content: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[Task(title: "title", description: "description")],
),
actions: <Widget>[Text("add")],
);
}
}
130 changes: 70 additions & 60 deletions frontend/lib/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import 'package:flutter/material.dart';
import 'package:src/task.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:src/widgets/interactive_task.dart';
import 'package:date_format/date_format.dart';

class Task extends StatefulWidget {
const Task(
{Key? key,
required this.title,
required this.description,
required this.ds})
{Key? key, required this.title, required this.description, this.ds})
: super(key: key);
final String title;
final String description;
final DocumentSnapshot ds;
final DocumentSnapshot? ds;

@override
State<Task> createState() => _Task();
Expand All @@ -21,70 +20,81 @@ class Task extends StatefulWidget {
class _Task extends State<Task> {
bool _done = false;

@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
String due = "new";
try {
DateTime date =
DateTime.parse(widget.ds!.data()["dueDate"].toDate().toString());
due = "Due " + formatDate(date, [M, ' ', d]);
} catch (e) {}
if (!_done) {
return Center(
child: Container(
margin: const EdgeInsets.all(4.0),
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: !_done ? Colors.white : Colors.green,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 2,
blurRadius: 6,
offset: const Offset(0, 3), // changes position of shadow
),
],
),
width: MediaQuery.of(context).size.width * 0.90,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
widget.title,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 18),
),
child: Container(
margin: widget.ds != null
? const EdgeInsets.all(0.0)
: const EdgeInsets.only(),
padding: widget.ds != null
? const EdgeInsets.all(0.0)
: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: widget.ds != null ? Colors.white : Colors.white,
),
width: MediaQuery.of(context).size.width,
height: 100,
child: Column(
children: [
Stack(children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.05,
width: MediaQuery.of(context).size.width * 0.40,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
widget.title,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 16),
),
padding: const EdgeInsets.all(8.0),
),
IconButton(
icon: const Icon(Icons.check_rounded),
onPressed: () {
setState(() {
FirebaseFirestore firestore =
FirebaseFirestore.instance;
CollectionReference tasks =
firestore.collection('tasks');
tasks.doc(widget.ds.id).delete();
_done = !_done;
});
},
),
],
),
Container(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
widget.description,
),
padding: const EdgeInsets.all(8.0),
),
padding: const EdgeInsets.all(5.0),
],
),
Positioned(
child: Text(
due,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13,
color: Colors.grey),
),
],
)));
right: 2,
)
]),
Container(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
widget.description,
),
),
padding: const EdgeInsets.all(5.0),
),
],
),
),
);
} else {
return Center();
return const Center();
}
}
}
Loading

0 comments on commit c44a083

Please sign in to comment.