Skip to content

Commit

Permalink
add all functonal features
Browse files Browse the repository at this point in the history
  • Loading branch information
saminsohag committed Nov 24, 2021
1 parent 0907b3a commit f4574a1
Show file tree
Hide file tree
Showing 9 changed files with 670 additions and 181 deletions.
5 changes: 3 additions & 2 deletions lib/src/common/widgets/coustome_snack_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ class CoustomeSnackBar extends SnackBar {
{Key? key, required Widget content, bool isFailed = false})
: super(
key: key,
backgroundColor:
(isFailed) ? Colors.red : Theme.of(context).primaryColor,
backgroundColor: (isFailed)
? Theme.of(context).errorColor
: Theme.of(context).primaryColor,
padding: const EdgeInsets.only(
left: 20,
right: 8,
Expand Down
12 changes: 12 additions & 0 deletions lib/src/features/content/controllers/edit_mode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter/material.dart';

class EditMode with ChangeNotifier {
bool _enabled = false;
bool get enabled => _enabled;
bool get notEnabled => !_enabled;
set setEnabled(bool value) {
if (_enabled == value) return;
_enabled = value;
notifyListeners();
}
}
158 changes: 158 additions & 0 deletions lib/src/features/content/pages/content.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:gst_todo/src/common/widgets/coustome_snack_bar.dart';
import 'package:gst_todo/src/features/content/controllers/edit_mode.dart';

class ContentPage extends StatefulWidget {
const ContentPage({Key? key, required this.documentSnapshot})
: super(key: key);
final QueryDocumentSnapshot<Map<String, dynamic>> documentSnapshot;

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

class _ContentPageState extends State<ContentPage> {
final EditMode _editMode = EditMode();
late final TextEditingController _textController;
@override
void initState() {
_textController =
TextEditingController(text: widget.documentSnapshot.data()["text"]);
super.initState();
}

@override
void dispose() {
super.dispose();
_editMode.dispose();
_textController.dispose();
}

@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _editMode,
builder: (context, child) {
return Scaffold(
appBar: AppBar(
title: const Text("Content"),
),
body: StreamBuilder<DocumentSnapshot<Map<String, dynamic>>>(
stream: widget.documentSnapshot.reference.snapshots(),
initialData: widget.documentSnapshot,
builder: (context, snapshot) {
return Container(
color: Theme.of(context).disabledColor.withOpacity(0.2),
child: Column(
children: [
Expanded(
child: ListView(
padding: const EdgeInsets.all(10),
children: [
Container(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(10),
),
constraints: const BoxConstraints(minHeight: 120),
child: Padding(
padding:
EdgeInsets.all(_editMode.enabled ? 15 : 25),
child: Builder(builder: (context) {
if (_editMode.enabled) {
return TextField(
controller: _textController,
maxLines: null,
style: const TextStyle(
fontSize: 18,
),
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(10),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.black,
),
borderRadius: BorderRadius.circular(10),
),
),
);
} else {
return SelectableText(
"${snapshot.data!.data()!["text"]}",
style: const TextStyle(fontSize: 18),
);
}
}),
),
),
],
),
),
Container(
color: Theme.of(context).cardColor,
child: Row(
children: [
if (_editMode.enabled) ...[
Expanded(
child: TextButton(
onPressed: () {
_editMode.setEnabled = _editMode.notEnabled;
},
child: const Text(
"Cancle",
),
style: TextButton.styleFrom(
primary: Theme.of(context).errorColor,
),
),
),
Expanded(
child: TextButton(
onPressed: () {
if (_textController.text.isEmpty) {
ScaffoldMessenger.of(context)
.hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
CoustomeSnackBar(
context,
content: const Text(
"! Text is Empty. Failed"),
isFailed: true,
),
);
return;
}
snapshot.data!.reference
.update({"text": _textController.text});
_editMode.setEnabled = _editMode.notEnabled;
},
child: const Text("Save"),
),
),
],
if (_editMode.notEnabled) ...[
Expanded(
child: TextButton(
onPressed: () {
_textController.text =
snapshot.data!.data()!["text"] ?? "";
_editMode.setEnabled = _editMode.notEnabled;
},
child: const Text("Edit"),
),
),
],
],
),
)
],
),
);
},
),
);
},
);
}
}
139 changes: 76 additions & 63 deletions lib/src/features/home/pages/done.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gst_todo/src/features/home/widgets/edit_university_detail_alert_dialog.dart';
import 'package:gst_todo/src/features/uviversity_details.page/pages/university_pages.dart';

class DoneUniversityPage extends StatefulWidget {
Expand All @@ -15,72 +16,84 @@ class _DoneUniversityPageState extends State<DoneUniversityPage> {
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
stream: FirebaseFirestore.instance
.collection("users")
.doc(FirebaseAuth.instance.currentUser!.uid)
.collection("university")
.orderBy("universityName")
.where(
"done",
isEqualTo: true,
)
.snapshots(includeMetadataChanges: true),
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data!.docs.isEmpty) {
return const Center(
child: Text("Empty"),
);
}
return ListView.builder(
padding: const EdgeInsets.only(
bottom: 70,
),
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
return Card(
elevation: 3,
child: InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => UniversityDetailPage(
documentSnapshot: snapshot.data!.docs[index],
),
stream: FirebaseFirestore.instance
.collection("users")
.doc(FirebaseAuth.instance.currentUser!.uid)
.collection("university")
.orderBy("universityName")
.where(
"done",
isEqualTo: true,
)
.snapshots(includeMetadataChanges: true),
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data!.docs.isEmpty) {
return const Center(
child: Text("Empty"),
);
}
return ListView.builder(
padding: const EdgeInsets.only(
bottom: 70,
),
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
return Card(
elevation: 3,
child: InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => UniversityDetailPage(
documentSnapshot: snapshot.data!.docs[index],
),
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
children: [
(snapshot.data!.docs[index].metadata.hasPendingWrites)
? const SizedBox(
width: 20,
)
: Icon(
Icons.check_box,
color: Theme.of(context).primaryColor,
size: 20,
),
Expanded(
child: ListTile(
title: Text(
"${snapshot.data!.docs[index].data()["universityName"] ?? "Unkonwn"}"),
),
),
],
),
);
},
onLongPress: () {
showCupertinoDialog(
barrierDismissible: true,
context: context,
builder: (context) {
return EditUniversityAlertDialog(
documentSnapshot: snapshot.data!.docs[index],
);
},
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
children: [
(snapshot.data!.docs[index].metadata.hasPendingWrites)
? const SizedBox(
width: 20,
)
: Icon(
Icons.check_box,
color: Theme.of(context).primaryColor,
size: 20,
),
Expanded(
child: ListTile(
title: Text(
"${snapshot.data!.docs[index].data()["universityName"] ?? "Unkonwn"}"),
),
),
],
),
),
);
},
);
} else {
return const Center(
child: CupertinoActivityIndicator(),
);
}
});
),
);
},
);
} else {
return const Center(
child: CupertinoActivityIndicator(),
);
}
},
);
}
}
12 changes: 12 additions & 0 deletions lib/src/features/home/pages/pending.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gst_todo/src/features/home/widgets/edit_university_detail_alert_dialog.dart';
import 'package:gst_todo/src/features/uviversity_details.page/pages/university_pages.dart';

class PendingUniversityPage extends StatefulWidget {
Expand Down Expand Up @@ -50,6 +51,17 @@ class _PendingUniversityPageState extends State<PendingUniversityPage> {
),
);
},
onLongPress: () {
showCupertinoDialog(
barrierDismissible: true,
context: context,
builder: (context) {
return EditUniversityAlertDialog(
documentSnapshot: snapshot.data!.docs[index],
);
},
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
Expand Down
Loading

0 comments on commit f4574a1

Please sign in to comment.