Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza4585 committed Aug 28, 2023
1 parent 5f2266b commit bf1f96f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 42 deletions.
3 changes: 2 additions & 1 deletion lib/data/firestor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ class Firestore_Datasource {
}
}

Stream<QuerySnapshot> stream() {
Stream<QuerySnapshot> stream(bool isDone) {
return _firestore
.collection('users')
.doc(_auth.currentUser!.uid)
.collection('notes')
.where('isDon', isEqualTo: isDone)
.snapshots();
}

Expand Down
69 changes: 30 additions & 39 deletions lib/screen/home.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_to_do_list/const/colors.dart';
import 'package:flutter_to_do_list/data/firestor.dart';
import 'package:flutter_to_do_list/screen/add_note_screen.dart';
import 'package:flutter_to_do_list/widgets/task_widgets.dart';
import 'package:flutter_to_do_list/widgets/stream_note.dart';

class Home_Screen extends StatefulWidget {
const Home_Screen({super.key});
Expand Down Expand Up @@ -34,41 +31,35 @@ class _Home_ScreenState extends State<Home_Screen> {
),
),
body: SafeArea(
child: NotificationListener<UserScrollNotification>(
onNotification: (notification) {
if (notification.direction == ScrollDirection.forward) {
setState(() {
show = true;
});
}
if (notification.direction == ScrollDirection.reverse) {
setState(() {
show = false;
});
}
return true;
},
child: StreamBuilder<QuerySnapshot>(
stream: Firestore_Datasource().stream(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
}
final noteslist = Firestore_Datasource().getNotes(snapshot);
return ListView.builder(
itemBuilder: (context, index) {
final note = noteslist[index];
return Dismissible(
key: UniqueKey(),
onDismissed: (direction) {
Firestore_Datasource().delet_note(note.id);
},
child: Task_Widget(note));
},
itemCount: noteslist.length,
);
}),
)),
child: NotificationListener<UserScrollNotification>(
onNotification: (notification) {
if (notification.direction == ScrollDirection.forward) {
setState(() {
show = true;
});
}
if (notification.direction == ScrollDirection.reverse) {
setState(() {
show = false;
});
}
return true;
},
child: Column(
children: [
Stream_note(false),
Text(
'isDone',
style: TextStyle(
fontSize: 16,
color: Colors.grey.shade500,
fontWeight: FontWeight.bold),
),
Stream_note(true),
],
),
),
),
);
}
}
5 changes: 3 additions & 2 deletions lib/widgets/stream_note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import 'package:flutter_to_do_list/widgets/task_widgets.dart';
import '../data/firestor.dart';

class Stream_note extends StatelessWidget {
const Stream_note({super.key});
bool done;
Stream_note(this.done, {super.key});

@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: Firestore_Datasource().stream(),
stream: Firestore_Datasource().stream(done),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
Expand Down

0 comments on commit bf1f96f

Please sign in to comment.