Skip to content

Commit

Permalink
network error bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
WaniAthar committed Mar 19, 2023
1 parent 9a15255 commit 3a8c7b2
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 15 deletions.
9 changes: 9 additions & 0 deletions lib/api/attendance_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';

class API extends ChangeNotifier {
// your api here
}
14 changes: 3 additions & 11 deletions lib/homepage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class HomePage extends StatelessWidget {
future: api.getData(),
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
// Show shimmer effect while data is loading
return _buildShimmerEffect();
} else if (snapshot.hasError) {
return Column(
Expand All @@ -37,9 +36,7 @@ class HomePage extends StatelessWidget {
)),
],
);
}
else {
api.isDataFetched = true;
} else {
return _buildData(api);
}
},
Expand Down Expand Up @@ -94,10 +91,7 @@ class HomePage extends StatelessWidget {
child: Lottie.asset(
"assets/lottieanimations/139432-person-riding-bicycle.json"),
),
Text(
api.personalData != null && api.personalData.isNotEmpty
? '${api.personalData['name']}'
: 'Personal data is null or empty',
Text('${api.personalData['name']}',
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 25,
Expand All @@ -110,9 +104,7 @@ class HomePage extends StatelessWidget {
endIndent: 100,
),
Text(
api.personalData != null && api.personalData.isNotEmpty
? '${api.personalData['usn']}'
: 'Personal data is null or empty',
'${api.personalData['usn']}',
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 15,
Expand Down
37 changes: 33 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ class _SLiderState extends State<SLider> {
highlightColor: Colors.grey[100]!);
} else {
return Text(
'${api.personalData['semester']}', //semester
api.attendanceData == null
? ""
: '${api.personalData['semester']}', //semester
style: GoogleFonts.poppins(
fontSize: 30, fontWeight: FontWeight.bold),
);
Expand All @@ -347,9 +349,7 @@ class _SLiderState extends State<SLider> {

Flexible(
child: FutureBuilder<void>(
future: api.isDataFetched == false
? api.getData()
: Future(() => null),
future: api.getData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
// show shimmer effect while waiting for data
Expand Down Expand Up @@ -387,6 +387,35 @@ class _SLiderState extends State<SLider> {
fontWeight: FontWeight.bold,
color: Colors.red),
textAlign: TextAlign.center),
const Padding(padding: EdgeInsets.only(top: 10)),
Text(
"If the problem persists, please check your USN and DOB and try again",
style: GoogleFonts.poppins(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.red),
textAlign: TextAlign.center),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Click the ",
style: GoogleFonts.poppins(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.red),
textAlign: TextAlign.center),
const Icon(
Icons.person,
color: Colors.red,
),
Text(" icon to change your USN and/or DOB",
style: GoogleFonts.poppins(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.red),
textAlign: TextAlign.center),
],
),
],
),
);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added md_files/flutter_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md_files/flutter_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md_files/flutter_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md_files/flutter_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3a8c7b2

Please sign in to comment.