Skip to content

Commit

Permalink
Merge pull request #9 from Rift3000/main
Browse files Browse the repository at this point in the history
Added a Home Screen and the ability to add tasks
  • Loading branch information
hanskokx authored Apr 9, 2021
2 parents 62a07f0 + f5edd46 commit c74fcf6
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 16 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ Check out designs we are considering.
<img src="notes2.png" width="250">
</p>

<br/>

### Progress so far
Rift's log 4/6/2021

<p float="left">
<img src="progress.jpg" width="250">
&nbsp;&nbsp;
<img src="progress2.jpg" width="250">
</p>
22 changes: 18 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import 'package:flutter/material.dart';
import 'screens/tasks_screen.dart';
import 'package:provider/provider.dart';
import 'models/task_data.dart';
import 'screens/home.dart';
import 'models/task_home_data.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => TaskData(),
return MultiProvider(
providers: [
ChangeNotifierProvider<TaskData>(create: (context) => TaskData()),
ChangeNotifierProvider<TaskListHome>(
create: (context) => TaskListHome()),
],
child: MaterialApp(
home: TasksScreen(),
theme: ThemeData(
primaryColor: Colors.lightBlueAccent,
accentColor: Colors.deepPurpleAccent,
canvasColor: Colors.white,
shadowColor: Colors.black,
errorColor: Colors.red,
splashColor: Colors.lightBlue,
),
debugShowCheckedModeBanner: false,
home: Home(),
),
);
}
Expand Down
9 changes: 9 additions & 0 deletions lib/models/task.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';

class Task {
final String name;
bool isDone;
Expand All @@ -8,3 +10,10 @@ class Task {
isDone = !isDone;
}
}

class TaskList {
final String title;
Icon taskIcon = Icon(Icons.alarm);

TaskList({@required this.title, this.taskIcon});
}
33 changes: 33 additions & 0 deletions lib/models/task_home_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'task.dart';

class TaskListHome extends ChangeNotifier {
List<TaskList> taskList = [
TaskList(title: "Rift's Corner", taskIcon: Icon(Icons.alarm)),
TaskList(title: "Hans' Corner", taskIcon: Icon(Icons.run_circle)),
TaskList(title: "Buy a Mouse", taskIcon: Icon(Icons.mouse))
];

int get taskLength {
return taskList.length;
}

bool show = false;
String textTitle;

void toggleError() {
show = !show;
notifyListeners();
}

void addTask(String myTaskTitle) {
final task = TaskList(title: myTaskTitle);
taskList.add(task);
notifyListeners();
}

void deleteTask(TaskList task) {
taskList.remove(task);
notifyListeners();
}
}
12 changes: 8 additions & 4 deletions lib/screens/add_task_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import 'package:u_do/models/task.dart';
import 'package:u_do/models/task_data.dart';

//This allows us to add tasks to the ListView
class AddTaskScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand All @@ -13,7 +14,7 @@ class AddTaskScreen extends StatelessWidget {
child: Container(
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
color: Theme.of(context).canvasColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
Expand All @@ -27,7 +28,7 @@ class AddTaskScreen extends StatelessWidget {
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 30.0,
color: Colors.lightBlueAccent,
color: Theme.of(context).primaryColor,
),
),
TextField(
Expand All @@ -41,13 +42,16 @@ class AddTaskScreen extends StatelessWidget {
child: Text(
'Add',
style: TextStyle(
color: Colors.white,
color: Theme.of(context).canvasColor,
),
),
onPressed: () {
Provider.of<TaskData>(context).addTask(newTaskTitle);
Provider.of<TaskData>(context, listen: false)
.addTask(newTaskTitle);
Navigator.pop(context);
},
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor),
),
],
),
Expand Down
200 changes: 200 additions & 0 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:u_do/models/task_home_data.dart';
import 'package:u_do/screens/tasks_screen.dart';

//This widget displays the Home Screen
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
iconTheme: IconThemeData(color: Theme.of(context).canvasColor),
),
drawer: Drawer(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [Text("Placeholder here"), Text("Placeholder here")],
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) => addTaskListPopup(context),
);
},
label: Text(
"Create",
style: TextStyle(color: Theme.of(context).canvasColor),
),
backgroundColor: Theme.of(context).primaryColor,
),
body: TaskHome(),
);
}
}

//This widgets contains all the TaskList for users
class TaskHome extends StatelessWidget {
final List<Map> myProducts =
List.generate(3, (index) => {"id": index, "name": "Product $index"})
.toList();

@override
Widget build(BuildContext context) {
double textSize = MediaQuery.of(context).size.width / 20;
return Padding(
padding: const EdgeInsets.all(8.0),
child: Consumer<TaskListHome>(builder: (context, tasklist, child) {
return GridView.builder(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 400,
childAspectRatio: 3 / 3,
crossAxisSpacing: 20,
mainAxisSpacing: 20),
itemCount: tasklist.taskLength,
itemBuilder: (BuildContext context, index) {
return GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => TasksScreen()));
},
child: Card(
elevation: 5.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.alarm,
color: Theme.of(context).canvasColor,
size: 50.0,
),
SizedBox(
height: 20.0,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Text(
tasklist.taskList[index].title,
style: TextStyle(
color: Theme.of(context).canvasColor,
fontSize: textSize > 10 ? textSize : 10,
fontWeight: FontWeight.w800),
textAlign: TextAlign.center,
),
),
]),
color: Theme.of(context).accentColor,
),
);
});
}));
}
}

//This popup allows the user to add a task
Widget addTaskListPopup(BuildContext context) {
String title;
double textSize = MediaQuery.of(context).size.width / 20;

return AlertDialog(
backgroundColor: Theme.of(context).accentColor,
title: Center(
child: Text('Add A Task',
style: TextStyle(
color: Theme.of(context).canvasColor,
fontSize: textSize > 10 ? textSize : 10,
fontWeight: FontWeight.w700,
decoration: TextDecoration.underline)),
),
content: Consumer<TaskListHome>(builder: (context, alert, child) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Stack(
alignment: Alignment.topRight,
clipBehavior: Clip.none,
children: <Widget>[
TextFormField(
cursorColor: Theme.of(context).shadowColor,
autocorrect: true,
onChanged: (newTitle) {
title = newTitle;
},
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).shadowColor, fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Theme.of(context).canvasColor,
border: OutlineInputBorder(borderSide: BorderSide.none),
suffixIcon: alert.show
? IconButton(
icon: Icon(
Icons.error,
color: Theme.of(context).errorColor,
),
onPressed: () {
alert.toggleError();
},
)
: null,
hintText: "Please do not leave the title blank"),
),
Positioned(
top: 130,
right: 22,
//You can use your own custom tooltip widget over here in place of below Container
child: alert.show
? Container(
width: 270,
height: 50,
decoration: BoxDecoration(
color: Theme.of(context).canvasColor,
border: Border.all(
color: Theme.of(context).errorColor,
width: 2.0),
borderRadius: BorderRadius.circular(10)),
padding: EdgeInsets.symmetric(horizontal: 10),
child: Center(
child: Text(
"Please enter a Title!",
),
),
)
: Container(),
),
SizedBox(
height: 30.0,
),
],
),
SizedBox(
height: 30.0,
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).splashColor,
elevation: 5.0,
padding: EdgeInsets.all(20.0)),
onPressed: () {
if (title != null) {
Provider.of<TaskListHome>(context, listen: false)
.addTask(title);
Navigator.of(context).pop();
alert.show = false;
} else {
alert.toggleError();
}
},
child: Text('Add Task',
style: TextStyle(
color: Theme.of(context).canvasColor, fontSize: 20.0)),
),
],
);
}));
}
Loading

0 comments on commit c74fcf6

Please sign in to comment.