Skip to content

Commit 903938c

Browse files
committed
added changes for production
Signed-off-by: Manas Malla <manasmalla.dev@gmail.com>
1 parent ea70d7c commit 903938c

File tree

9 files changed

+127
-65
lines changed

9 files changed

+127
-65
lines changed

lib/data/semester.dart

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class Subject {
161161
final String title;
162162
final String description;
163163
final IconData icon;
164-
final double progress;
164+
final ValueNotifier<double> progress;
165165
final String image;
166166
final List<Unit> units;
167167
final List<Instructor> instructor;
@@ -174,7 +174,7 @@ class Subject {
174174
required this.title,
175175
required this.description,
176176
this.icon = Icons.category_outlined,
177-
this.progress = 0.0,
177+
required this.progress,
178178
this.image =
179179
"https://images.squarespace-cdn.com/content/v1/570b9bd42fe131a6e20717c2/1730901328712-ARXW9LQ4S2MVG2PULIKV/Gitam_Banner.jpg?format=2500w",
180180
this.units = const [],
@@ -195,7 +195,9 @@ class Subject {
195195
description: data["description"],
196196
icon: IconData(data["icon"], fontFamily: "MaterialIcons"),
197197
image: data["image"],
198-
progress: double.tryParse(data["progress"].toString()) ?? 0,
198+
progress: ValueNotifier(
199+
double.tryParse(data["progress"].toString()) ?? 0,
200+
),
199201
units: List<Unit>.from(
200202
data["units"].map((unit) {
201203
return Unit.fromMap(unit);
@@ -230,19 +232,20 @@ class Subject {
230232
}
231233

232234
copyWithProgress(double progress) {
233-
return Subject(
234-
courseId: courseId,
235-
courseCategory: courseCategory,
236-
title: title,
237-
description: description,
238-
icon: icon,
239-
image: image,
240-
progress: progress,
241-
units: units,
242-
instructor: instructor,
243-
rating: rating,
244-
reviews: reviews,
245-
);
235+
this.progress.value = progress;
236+
// return Subject(
237+
// courseId: courseId,
238+
// courseCategory: courseCategory,
239+
// title: title,
240+
// description: description,
241+
// icon: icon,
242+
// image: image,
243+
// progress: progress,
244+
// units: units,
245+
// instructor: instructor,
246+
// rating: rating,
247+
// reviews: reviews,
248+
// );
246249
}
247250
}
248251

lib/domain/fetch_resources.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ Future<String> addCompletedResource(
9999
},
100100
).then((response) {
101101
if (response.statusCode == 200) {
102-
return json.decode(response.body);
102+
final d = json.decode(response.body);
103+
print(d);
104+
final newProgress = d["progress"];
105+
if (newProgress != null) {
106+
final s2 = (Injector.semesterRepository.semester?.courses.values
107+
.fold([], (a, b) => [...a, ...b])
108+
.firstWhere((course) => course.courseId == res.courseId)
109+
as Subject)
110+
.copyWithProgress(newProgress);
111+
}
112+
return d;
103113
} else {
104114
try {
105115
final result = json.decode(response.body);

lib/home_page.dart

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,13 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
384384
overflow: TextOverflow.ellipsis,
385385
),
386386
SizedBox(height: 16),
387-
LinearProgressIndicator(
388-
value: subject.progress / 100,
387+
ValueListenableBuilder(
388+
valueListenable: subject.progress,
389+
builder: (context, value, child) {
390+
return LinearProgressIndicator(
391+
value: value / 100,
392+
);
393+
},
389394
),
390395
],
391396
),
@@ -721,12 +726,17 @@ class SubjectCardExpanded extends StatelessWidget {
721726
),
722727
),
723728
Spacer(),
724-
LinearProgressIndicator(
725-
backgroundColor: Color(0xFF053F5C),
726-
value: subject.progress,
727-
borderRadius: BorderRadius.circular(12),
728-
minHeight: 6,
729-
color: Color(0xFFF27F0C),
729+
ValueListenableBuilder(
730+
valueListenable: subject.progress,
731+
builder: (context, value, child) {
732+
return LinearProgressIndicator(
733+
backgroundColor: Color(0xFF053F5C),
734+
value: value,
735+
borderRadius: BorderRadius.circular(12),
736+
minHeight: 6,
737+
color: Color(0xFFF27F0C),
738+
);
739+
},
730740
),
731741
],
732742
),

lib/login_screen.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,11 @@ class _LoginScreenState extends State<LoginScreen> {
245245
"deviceId":
246246
await fetchDeviceId(),
247247
"fcmToken":
248-
await FirebaseMessaging
249-
.instance
250-
.getToken(),
248+
Platform.isWindows
249+
? "windows"
250+
: await FirebaseMessaging
251+
.instance
252+
.getToken(),
251253
}),
252254
);
253255
if (loginRequest.statusCode ==
@@ -593,8 +595,11 @@ class _LoginScreenState extends State<LoginScreen> {
593595
"name": name,
594596
"courses": res.toSet().toList(),
595597
"fcmToken":
596-
await FirebaseMessaging.instance
597-
.getToken(),
598+
Platform.isWindows
599+
? "windows"
600+
: await FirebaseMessaging
601+
.instance
602+
.getToken(),
598603
};
599604
print("PAYLOAD: $payload");
600605
final signupRequest = await post(
@@ -754,6 +759,11 @@ class _LoginScreenState extends State<LoginScreen> {
754759
".. as we break some walls for you.",
755760
style: Theme.of(context).textTheme.bodyMedium,
756761
),
762+
Text(
763+
"This may take a while, upto 2 minutes depending on your network.",
764+
style: Theme.of(context).textTheme.bodySmall
765+
?.copyWith(fontStyle: FontStyle.italic),
766+
),
757767
],
758768
),
759769
),

lib/main.dart

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,7 @@ Future<void> main() async {
3434
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
3535

3636
HttpOverrides.global = new MyHttpOverrides();
37-
final notificationSettings = await FirebaseMessaging.instance
38-
.requestPermission(
39-
provisional: false,
40-
alert: true,
41-
badge: true,
42-
sound: true,
43-
announcement: true,
44-
criticalAlert: true,
45-
);
46-
final apnsToken = await FirebaseMessaging.instance.getAPNSToken();
47-
print("APNS Token: $apnsToken");
48-
print('User granted permission: ${notificationSettings.authorizationStatus}');
49-
if (notificationSettings.authorizationStatus ==
50-
AuthorizationStatus.authorized) {
51-
print('User granted permission');
52-
} else if (notificationSettings.authorizationStatus ==
53-
AuthorizationStatus.provisional) {
54-
print('User granted provisional permission');
55-
} else {
56-
// requested permission
37+
if (!Platform.isWindows) {
5738
final notificationSettings = await FirebaseMessaging.instance
5839
.requestPermission(
5940
provisional: false,
@@ -63,13 +44,34 @@ Future<void> main() async {
6344
announcement: true,
6445
criticalAlert: true,
6546
);
47+
final apnsToken = await FirebaseMessaging.instance.getAPNSToken();
48+
print("APNS Token: $apnsToken");
49+
print(
50+
'User granted permission: ${notificationSettings.authorizationStatus}',
51+
);
52+
if (notificationSettings.authorizationStatus ==
53+
AuthorizationStatus.authorized) {
54+
print('User granted permission');
55+
} else if (notificationSettings.authorizationStatus ==
56+
AuthorizationStatus.provisional) {
57+
print('User granted provisional permission');
58+
} else {
59+
// requested permission
60+
final notificationSettings = await FirebaseMessaging.instance
61+
.requestPermission(
62+
provisional: false,
63+
alert: true,
64+
badge: true,
65+
sound: true,
66+
announcement: true,
67+
criticalAlert: true,
68+
);
69+
}
70+
print(
71+
'Firebase Messaging Token: ${await FirebaseMessaging.instance.getToken()}',
72+
);
73+
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
6674
}
67-
// for handling the recieved notifications on windows, we are manualloy showing the notification using flutter local notifications
68-
69-
print(
70-
'Firebase Messaging Token: ${await FirebaseMessaging.instance.getToken()}',
71-
);
72-
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
7375

7476
runApp(const MyApp());
7577
}

lib/pdf_doc/pdf_main.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class _PDFViewPageState extends State<PDFViewPage> with WidgetsBindingObserver {
2727
final showLeftPane = ValueNotifier<bool>(false);
2828
final outline = ValueNotifier<List<PdfOutlineNode>?>(null);
2929
final textSearcher = ValueNotifier<PdfTextSearcher?>(null);
30+
3031
final _markers = <int, List<Marker>>{};
3132

3233
@override
@@ -270,6 +271,18 @@ class _PDFViewPageState extends State<PDFViewPage> with WidgetsBindingObserver {
270271
(context, thumbSize, pageNumber, controller) =>
271272
Container(color: Colors.red),
272273
),
274+
Align(
275+
alignment: Alignment.bottomCenter,
276+
child: Padding(
277+
padding: const EdgeInsets.only(bottom: 24.0),
278+
child: FilledButton(
279+
onPressed: () {
280+
widget.onAddResource();
281+
},
282+
child: Text("Next"),
283+
),
284+
),
285+
),
273286
],
274287
loadingBannerBuilder:
275288
(context, bytesDownloaded, totalBytes) => Center(

lib/splash_screen.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class SplashScreen extends StatelessWidget {
2424
} else {
2525
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
2626
try {
27-
FirebaseAuth.instance.currentUser!.getIdToken(true).then((token) {
27+
FirebaseAuth.instance.currentUser!.getIdToken(true).then((
28+
token,
29+
) async {
2830
if (token == null) {
2931
if (context.mounted) {
3032
ScaffoldMessenger.of(context).showSnackBar(
@@ -34,7 +36,7 @@ class SplashScreen extends StatelessWidget {
3436
return;
3537
}
3638
try {
37-
fetchCart(context);
39+
await fetchCart(context);
3840
Injector.semesterRepository
3941
.fetchSemester(token, () {
4042
ScaffoldMessenger.of(context).showSnackBar(

lib/subject_page.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,26 @@ class SubjectPage extends StatelessWidget {
158158
overflow: TextOverflow.ellipsis,
159159
),
160160
SizedBox(height: 20),
161-
LinearProgressIndicator(value: subject.progress / 100),
161+
ValueListenableBuilder(
162+
valueListenable: subject.progress,
163+
builder: (context, value, child) {
164+
return LinearProgressIndicator(value: value / 100);
165+
},
166+
),
162167
SizedBox(height: 8),
163168
Opacity(
164169
opacity: 0.3,
165170
child: Align(
166171
alignment: Alignment.bottomRight,
167-
child: Text(
168-
"${(subject.progress).toInt()}% completed",
169-
style: Theme.of(context).textTheme.labelLarge
170-
?.copyWith(fontWeight: FontWeight.bold),
172+
child: ValueListenableBuilder(
173+
valueListenable: subject.progress,
174+
builder: (context, value, child) {
175+
return Text(
176+
"${(value).toInt()}% completed",
177+
style: Theme.of(context).textTheme.labelLarge
178+
?.copyWith(fontWeight: FontWeight.bold),
179+
);
180+
},
171181
),
172182
),
173183
),

lib/unit_resource_page.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ class _VideoPlayerWidgetState extends State<VideoPlayerWidget> {
830830

831831
ValueNotifier<double> zoomScale = ValueNotifier<double>(1.0);
832832
ValueNotifier<Offset> panOffset = ValueNotifier<Offset>(Offset(0, 0));
833+
ValueNotifier<bool> calledOnSubmitProgress = ValueNotifier<bool>(false);
833834

834835
@override
835836
void initState() {
@@ -842,8 +843,9 @@ class _VideoPlayerWidgetState extends State<VideoPlayerWidget> {
842843

843844
_initializeVideoPlayerFuture = _controller.initialize();
844845
_controller.addListener(() {
845-
if (_controller.value.position + Duration(seconds: 5) ==
846-
_controller.value.duration) {
846+
if (_controller.value.position >=
847+
_controller.value.duration - Duration(seconds: 5) &&
848+
!calledOnSubmitProgress.value) {
847849
widget.onPlayedVideo();
848850
}
849851
if (_controller.value.isCompleted) {

0 commit comments

Comments
 (0)