Skip to content

Commit 70cede2

Browse files
committed
Merge branch 'Samveg12-hacktober/SamvegShah'
2 parents 24ba798 + d5c4093 commit 70cede2

File tree

6 files changed

+202
-108
lines changed

6 files changed

+202
-108
lines changed

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
97C146E61CF9000F007C117D /* Project object */ = {
161161
isa = PBXProject;
162162
attributes = {
163-
LastUpgradeCheck = 1020;
163+
LastUpgradeCheck = 1300;
164164
ORGANIZATIONNAME = "";
165165
TargetAttributes = {
166166
97C146ED1CF9000F007C117D = {

ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1300"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

lib/screens/user_preferences.dart

Lines changed: 115 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,90 @@ import 'package:google_fonts/google_fonts.dart';
1010
String uID = FirebaseAuthService().getUID;
1111
DatabaseService _databaseService = DatabaseService(uid: uID);
1212

13+
class GenreChoice extends StatefulWidget {
14+
// const GenreChoice({ Key? key }) : super(key: key);
15+
16+
@override
17+
_GenreChoiceState createState() => _GenreChoiceState();
18+
}
19+
1320
class UserPreference extends StatefulWidget {
1421
final UserData? userData;
1522
const UserPreference(this.userData);
1623
@override
1724
_UserPreferenceState createState() => _UserPreferenceState();
1825
}
1926

27+
class _GenreChoiceState extends State<GenreChoice> {
28+
List<String> tags = [];
29+
@override
30+
Widget build(BuildContext context) {
31+
print('*******');
32+
// print(_author.text);
33+
// print(a);
34+
print(tags);
35+
// print(_user.value)
36+
37+
return ChipsChoice<String>.multiple(
38+
value: tags,
39+
onChanged: (List<String> val) => setState(() {
40+
tags = val;
41+
// a = a;
42+
// b = b;
43+
}),
44+
choiceItems: C2Choice.listFrom<String, String>(
45+
source: genres,
46+
value: (int i, String v) => v,
47+
label: (int i, String v) => v,
48+
tooltip: (int i, String v) => v,
49+
),
50+
choiceStyle: const C2ChoiceStyle(
51+
color: Colors.blue,
52+
borderRadius: BorderRadius.all(Radius.circular(5)),
53+
borderColor: Colors.green,
54+
),
55+
choiceActiveStyle: const C2ChoiceStyle(
56+
color: blackButton,
57+
),
58+
wrapped: true,
59+
);
60+
}
61+
}
62+
2063
class _UserPreferenceState extends State<UserPreference> {
2164
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
2265

23-
// final TextEditingController _author = TextEditingController();
24-
// final TextEditingController _book = TextEditingController();
66+
final TextEditingController _author = TextEditingController();
67+
final TextEditingController _book = TextEditingController();
2568

2669
List<String> tags = [];
70+
String a = '';
71+
String b = '';
2772

2873
@override
2974
Widget build(BuildContext context) {
75+
String favBook;
76+
String favAuthor;
3077
// final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
31-
final String? favBook = widget.userData!.preferences!['favBook'] as String?;
32-
final String? favAuthor =
78+
if (a == null && b == null) {
79+
print('helllllloooo');
80+
favBook = widget.userData!.preferences!['favBook'] as String;
81+
favAuthor = widget.userData!.preferences!['favAuthor'] as String;
82+
a = favBook;
83+
b = favAuthor;
84+
} else {
85+
print('{{}}}');
86+
favBook = a;
87+
favAuthor = b;
88+
}
89+
// final String? favBook = widget.userData!.preferences!['favBook'] as String?;
90+
// final String? favAuthor =
3391
widget.userData!.preferences!['favAuthor'] as String?;
3492
// final String location =
3593
// widget.userData.preferences['locationRange'] as String;
3694

3795
final TextEditingController _author =
38-
TextEditingController(text: favAuthor);
96+
TextEditingController(text: favAuthor);
3997
final TextEditingController _book = TextEditingController(text: favBook);
4098

4199
return Form(
@@ -46,7 +104,7 @@ class _UserPreferenceState extends State<UserPreference> {
46104
child: Text(
47105
'User Preferences',
48106
style:
49-
GoogleFonts.lato(color: Theme.of(context).colorScheme.primary),
107+
GoogleFonts.lato(color: Theme.of(context).colorScheme.primary),
50108
),
51109
),
52110
shape: const RoundedRectangleBorder(
@@ -57,15 +115,14 @@ class _UserPreferenceState extends State<UserPreference> {
57115
width: 250,
58116
child: SingleChildScrollView(
59117
child: Column(
60-
children: <Widget>[
118+
children: [
61119
const SizedBox(
62120
height: 20,
63121
),
64122
TextFormField(
65123
controller: _book,
66124
keyboardType: TextInputType.name,
67125
textAlign: TextAlign.start,
68-
// initialValue: favBook,
69126
decoration: InputDecoration(
70127
hintText: 'Favourite Book',
71128
fillColor: Theme.of(context).colorScheme.primary,
@@ -79,6 +136,7 @@ class _UserPreferenceState extends State<UserPreference> {
79136
return null;
80137
},
81138
onChanged: (String v) {
139+
a = v;
82140
print(v);
83141
},
84142
onSaved: (String? val) {
@@ -89,7 +147,6 @@ class _UserPreferenceState extends State<UserPreference> {
89147
height: 10,
90148
),
91149
TextFormField(
92-
// initialValue: favAuthor,
93150
controller: _author,
94151
keyboardType: TextInputType.name,
95152
textAlign: TextAlign.start,
@@ -105,12 +162,44 @@ class _UserPreferenceState extends State<UserPreference> {
105162
}
106163
return null;
107164
},
165+
onChanged: (String v) {
166+
b = v;
167+
// _author.text=v;
168+
print(v);
169+
},
108170
),
109171
const SizedBox(
110172
height: 20,
111173
),
112174
Text('Select Book genres', style: GoogleFonts.lato()),
113-
_genresChoice(),
175+
// _genresChoice(),
176+
Builder(builder: (BuildContext ctx) {
177+
return ChipsChoice<String>.multiple(
178+
value: tags,
179+
onChanged: (List<String> val) => setState(() {
180+
tags = val;
181+
a = a;
182+
b = b;
183+
}),
184+
choiceItems: C2Choice.listFrom<String, String>(
185+
source: genres,
186+
value: (int i, String v) => v,
187+
label: (int i, String v) => v,
188+
tooltip: (int i, String v) => v,
189+
),
190+
choiceStyle: const C2ChoiceStyle(
191+
color: Colors.blue,
192+
borderRadius: BorderRadius.all(Radius.circular(5)),
193+
borderColor: Colors.green,
194+
),
195+
choiceActiveStyle: const C2ChoiceStyle(
196+
color: blackButton,
197+
),
198+
wrapped: true,
199+
);
200+
}),
201+
202+
// GenreChoice(),
114203
],
115204
),
116205
),
@@ -120,9 +209,15 @@ class _UserPreferenceState extends State<UserPreference> {
120209
onPressed: () async {
121210
//Validate Author and BookName
122211
if (_formKey.currentState!.validate()) {
123-
_onSubmitTap();
124212
_formKey.currentState!.save();
125-
Navigator.pop(context);
213+
_onSubmitTap();
214+
if (mounted) {
215+
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
216+
content: Text('User preferences have been saved',
217+
style: TextStyle(color: blackButton)),
218+
duration: Duration(seconds: 3),
219+
));
220+
}
126221
}
127222
},
128223
child: Text(
@@ -146,37 +241,18 @@ class _UserPreferenceState extends State<UserPreference> {
146241
);
147242
}
148243

149-
ChipsChoice<String> _genresChoice() {
150-
return ChipsChoice<String>.multiple(
151-
value: tags,
152-
onChanged: (List<String> val) => setState(() => tags = val),
153-
choiceItems: C2Choice.listFrom<String, String>(
154-
source: genres,
155-
value: (i, v) => v,
156-
label: (i, v) => v,
157-
),
158-
choiceStyle: const C2ChoiceStyle(
159-
borderRadius: BorderRadius.all(Radius.circular(5)),
160-
borderColor: Colors.grey,
161-
),
162-
choiceActiveStyle: const C2ChoiceStyle(
163-
color: blackButton,
164-
),
165-
wrapped: true,
166-
);
167-
}
168-
169-
Future<void> _onSubmitTap() async {
244+
Future _onSubmitTap() async {
170245
final List<dynamic> items = tags.toList();
171-
items.removeRange(0, 1);
172-
print(items);
246+
173247
final List<String> selectedGenres = <String>[];
174248
for (final dynamic element in items) {
175249
final String x = element.toString();
176-
print(genres[int.parse(x)]);
177-
selectedGenres.add(genres[int.parse(x)]);
250+
251+
selectedGenres.add(x);
178252
}
179-
print(selectedGenres);
253+
180254
await _databaseService.updateGenres(selectedGenres);
255+
await _databaseService.updatePreferences(b, a);
256+
Navigator.pop(context);
181257
}
182-
}
258+
}

0 commit comments

Comments
 (0)