-
Notifications
You must be signed in to change notification settings - Fork 0
/
JournalPage.dart
160 lines (135 loc) · 6.51 KB
/
JournalPage.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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:google_fonts/google_fonts.dart';
import 'package:gratus/components/BottomNavBar.dart';
import 'package:gratus/components/view_grat_entry.dart';
import 'dart:math';
import '../Welcome.dart';
List<String> imageUrls = ['https://images.unsplash.com/photo-1438786657495-640937046d18?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80',
'https://images.unsplash.com/photo-1678723097718-8c7f5ece3a3c?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHx0b3BpYy1mZWVkfDJ8NnNNVmpUTFNrZVF8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=60',
'https://images.unsplash.com/photo-1678719510034-a2d3efb68e85?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=718&q=80',
'https://images.unsplash.com/photo-1678614034519-6d142721173f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=735&q=80',
'https://images.unsplash.com/photo-1678125690568-d3f224222aab?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80',];
class JournalPage extends StatefulWidget {
final User? user;
const JournalPage( {Key? key, this.user}) : super(key: key);
@override
State<JournalPage> createState() => _JournalPageState();
}
class _JournalPageState extends State<JournalPage> {
final List<String> entries=[];
@override
void initState() {
int randomIndex = Random().nextInt(imageUrls.length);
String selectedImageUrl = imageUrls[randomIndex];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xFF49DED2),
title: Text("Journal", style: GoogleFonts.inter()),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => GratitudePage(widget.user)),
);
},
),
),
body: Container(
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('gratitudeEntries')
.where('user', isEqualTo: widget.user?.uid)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
}
if (!snapshot.hasData) {
return Text('Loading...');
}
List entries =
snapshot.data!.docs.map((doc) => doc['entry']).toList();
List<DocumentSnapshot> testEntries = snapshot.data!.docs;
return Container(
child:
ListView.builder(
scrollDirection: Axis.vertical,
padding: const EdgeInsets.all(8),
itemCount: entries.length,
itemBuilder: (BuildContext context, int index) {
return Center(
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Stack(
children: [
Container(
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(15.0),
image: DecorationImage(
image: NetworkImage(imageUrls[ Random().nextInt(imageUrls.length)]),
fit: BoxFit.cover,
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: Offset(0, 3),
),
],
),
height: 350.0,
width: 250.0,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
color: Colors.black.withOpacity(0.4),
child: Text(
'Gratitude Entry',
style: TextStyle(
color: Colors.white,
fontSize: 28.0,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(height: 10.0),
Container(
color: Colors.black.withOpacity(0.4),
child: Text('${entries[index]}',style: GoogleFonts.inter(color: Colors.white),)
)
],
),
),
),
]
),
],
),
),
);
}
),
);
},
),
),
);
}
}