Skip to content

Commit

Permalink
Added shimmer effect and scroll view (#276)
Browse files Browse the repository at this point in the history
* added shimmer and scroll view

* added fetchFunction alongwith setState
  • Loading branch information
nb9960 authored Dec 11, 2020
1 parent dc6d88e commit c62c4ca
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 32 deletions.
14 changes: 11 additions & 3 deletions lib/pages/allEntities/allEntitiesPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ class _EntitiesPageState extends State<EntitiesPage> {
return true;
}

void reload() {
setState(() {});
void reload() async {
try {
await AppConstants.updateAndPopulateAllEntities();
setState(() {});
} on InternetConnectionException catch (_) {
AppConstants.internetErrorFlushBar.showFlushbar(context);
return;
} catch (err) {
print(err);
}
}

@override
Expand Down Expand Up @@ -80,7 +88,7 @@ class _EntitiesPageState extends State<EntitiesPage> {
return _buildAllEntitiesBodyPosts(context, posts, reload: reload);
} else {
return Center(
child: LoadingCircle,
child: EntityCustomWidgets.getPlaceholder(),
);
}
},
Expand Down
14 changes: 12 additions & 2 deletions lib/pages/allWorkshops/allWorkshopsPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:iit_app/model/colorConstants.dart';
import 'package:iit_app/ui/drawer.dart';
import 'package:iit_app/services/buildWorkshops.dart' as buildWorkshop;
import 'package:iit_app/ui/search_workshop.dart';
import 'package:iit_app/model/appConstants.dart';
import 'package:iit_app/data/internet_connection_interceptor.dart';

class AllWorkshopsScreen extends StatefulWidget {
@override
Expand All @@ -23,8 +25,16 @@ class _AllWorkshopsScreenState extends State<AllWorkshopsScreen>
super.initState();
}

void reload() {
setState(() {});
void reload() async {
try {
await AppConstants.service.getAllWorkshops();
setState(() {});
} on InternetConnectionException catch (_) {
AppConstants.internetErrorFlushBar.showFlushbar(context);
return;
} catch (err) {
print(err);
}
}

@override
Expand Down
14 changes: 12 additions & 2 deletions lib/screens/interestedScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:iit_app/pages/Home/homePage.dart';
import 'package:iit_app/ui/drawer.dart';
import 'package:iit_app/ui/text_style.dart';
import '../services/buildWorkshops.dart' as buildWorkhops;
import 'package:iit_app/data/internet_connection_interceptor.dart';

class InterestedScreen extends StatefulWidget {
@override
Expand All @@ -13,8 +14,17 @@ class InterestedScreen extends StatefulWidget {

class _InterestedScreenState extends State<InterestedScreen>
with SingleTickerProviderStateMixin {
void reload() {
setState(() {});
void reload() async {
try {
await AppConstants.service
.getInterestedWorkshops(AppConstants.djangoToken);
setState(() {});
} on InternetConnectionException catch (_) {
AppConstants.internetErrorFlushBar.showFlushbar(context);
return;
} catch (err) {
print(err);
}
}

@override
Expand Down
16 changes: 10 additions & 6 deletions lib/services/buildWorkshops.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ Widget buildCurrentWorkshopAndEventPosts(
{Function reload, bool isEvent}) {
Widget _builder(w) {
return w.length == 0
? Center(
child: Text('No Activity :(',
style:
TextStyle(color: ColorConstants.textColor, fontSize: 25)))
? SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Container(
alignment: Alignment.center,
height: MediaQuery.of(context).size.height - 250,
child: Text('No Activity :(',
style: TextStyle(
color: ColorConstants.textColor, fontSize: 25))),
)
: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
Expand Down Expand Up @@ -212,9 +217,8 @@ FutureBuilder<Response> buildAllWorkshopsBody(BuildContext context,

return _buildAllWorkshopsBodyPosts(context, posts, reload: reload);
} else {
// Show a loading indicator while waiting for the posts
return Center(
child: LoadingCircle,
child: WorkshopCustomWidgets.getPlaceholder(),
);
}
},
Expand Down
95 changes: 86 additions & 9 deletions lib/ui/entity_custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:iit_app/pages/club_entity/entityPage.dart';
import 'package:iit_app/ui/club_entity_common.dart';
import 'package:iit_app/ui/separator.dart';
import 'package:iit_app/ui/text_style.dart';
import 'package:skeleton_text/skeleton_text.dart';

class EntityCustomWidgets {
final BorderRadiusGeometry radius;
Expand All @@ -33,7 +34,7 @@ class EntityCustomWidgets {
Widget getPanel(
{@required ScrollController sc, @required EntityListPost entity}) {
return Container(
padding: EdgeInsets.only(top: 16.0),
padding: EdgeInsets.only(top: 20.0),
decoration: BoxDecoration(
borderRadius: radius,
color: ColorConstants.panelColor,
Expand Down Expand Up @@ -113,14 +114,13 @@ class EntityCustomWidgets {
return GestureDetector(
onTap: () {
if (horizontal)
Navigator.of(context)
.push(PageRouteBuilder(
pageBuilder: (_, __, ___) => EntityPage(entity: entity),
transitionsBuilder:
(context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
))
.then((value) => reload());
Navigator.of(context).push(PageRouteBuilder(
pageBuilder: (_, __, ___) => EntityPage(entity: entity),
transitionsBuilder:
(context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
));
// .then((value) => reload());
},
child: Container(
margin: const EdgeInsets.symmetric(
Expand All @@ -135,4 +135,81 @@ class EntityCustomWidgets {
),
));
}

static ListView getPlaceholder() {
final BorderRadius borderRadius = BorderRadius.circular(10.0);
return ListView.builder(
scrollDirection: Axis.vertical,
physics: BouncingScrollPhysics(),
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
decoration: BoxDecoration(
borderRadius: borderRadius, color: Colors.transparent),
child: Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ClipRRect(
borderRadius: borderRadius,
child: SkeletonAnimation(
child: Container(
width: 75.0,
height: 75.0,
decoration: BoxDecoration(
color: ColorConstants.shimmerSkeletonColor,
),
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 15.0,
bottom: 15.0,
),
child: ClipRRect(
borderRadius: borderRadius,
child: SkeletonAnimation(
child: Container(
height: 20.0,
width: MediaQuery.of(context).size.width * 0.7,
decoration: BoxDecoration(
color: ColorConstants.shimmerSkeletonColor),
),
),
),
),
Padding(
padding:
const EdgeInsets.only(left: 15.0, right: 5.0),
child: ClipRRect(
borderRadius: borderRadius,
child: SkeletonAnimation(
child: Container(
width: MediaQuery.of(context).size.width * 0.5,
height: 20.0,
decoration: BoxDecoration(
color: ColorConstants.shimmerSkeletonColor),
),
),
),
),
],
),
],
),
),
),
);
});
}
}
19 changes: 9 additions & 10 deletions lib/ui/workshop_custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,16 @@ class WorkshopCustomWidgets {
return GestureDetector(
onTap: horizontal
? () {
Navigator.of(context)
.push(
PageRouteBuilder(
pageBuilder: (_, __, ___) =>
WorkshopDetailPage(workshop: w, isPast: isPast),
transitionsBuilder: (context, animation,
secondaryAnimation, child) =>
Navigator.of(context).push(
PageRouteBuilder(
pageBuilder: (_, __, ___) =>
WorkshopDetailPage(workshop: w, isPast: isPast),
transitionsBuilder:
(context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
),
)
.then((value) => reload());
),
);
// .then((value) => reload());
try {
if (fabKey.currentState.isOpen) {
fabKey.currentState.close();
Expand Down

0 comments on commit c62c4ca

Please sign in to comment.