Skip to content

Commit

Permalink
Code Refactor and Cleanup (#48)
Browse files Browse the repository at this point in the history
* Code Refactor and Cleanup

* Empty page UI's

* Cleanup
  • Loading branch information
RohanDoshi21 committed Apr 14, 2023
1 parent e50235d commit 9ef643a
Show file tree
Hide file tree
Showing 33 changed files with 663 additions and 480 deletions.
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ dart_code_metrics:
- avoid-unused-parameters
- newline-before-return
- no-boolean-literal-compare
- no-empty-block
- prefer-trailing-comma
- prefer-conditional-expressions
- no-equal-then-else
1 change: 1 addition & 0 deletions assets/images/empty_spaceman.json

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions lib/config/remote_config.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:developer';

import 'package:firebase_remote_config/firebase_remote_config.dart';

import '../constants/urls.dart';
Expand All @@ -18,9 +16,7 @@ Future<void> remoteConfig() async {
EndPoints.privacyPolicyURL = remoteConfig.getString('privacyPolicy');
EndPoints.websiteURL = remoteConfig.getString('websiteUrl');
EndPoints.playStoreURL = remoteConfig.getString('playstoreUrl');
log(EndPoints.baseUrl as String);
log(EndPoints.sampleToken as String);
log(EndPoints.appLatestStableVersion as String);
EndPoints.sponsorsUrl = remoteConfig.getString('sponsorsUrl');

return;
}
1 change: 1 addition & 0 deletions lib/constants/images.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class AppImages {
static const eventDescriptionBackground =
'assets/images/event-description-bg.gif';
static const orangeRocket = 'assets/images/orange_rocket.json';
static const emptyMan = "assets/images/empty_spaceman.json";
}
1 change: 0 additions & 1 deletion lib/constants/models/registered_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class RegisteredEvent {
this.createdAt,
this.events,
this.status,

});

RegisteredEvent.fromJson(Map<String, dynamic> json) {
Expand Down
1 change: 1 addition & 0 deletions lib/constants/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class EndPoints {
static String? privacyPolicyURL;
static String? websiteURL;
static String? playStoreURL;
static String? sponsorsUrl;

static String events = '${baseUrl!}/events';
static String user = '${baseUrl!}/user/me';
Expand Down
1 change: 1 addition & 0 deletions lib/constants/utils/theme.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';

import '../colors.dart';

class Themes {
Expand Down
97 changes: 97 additions & 0 deletions lib/constants/widgets/empty_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';

import '../colors.dart';
import '../images.dart';
import '../styles.dart';

class EmptyPage extends StatelessWidget {
final String title;
final String errorMessage;
final VoidCallback? refreshFunction;

const EmptyPage({
required this.errorMessage,
super.key,
this.refreshFunction,
required this.title,
});

@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;

return Stack(
clipBehavior: Clip.none,
children: [
Container(
height: size.height * 0.35,
width: size.width * 0.6,
decoration: BoxDecoration(
color: AppColors.primary.withAlpha(150),
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
border: const Border.fromBorderSide(
BorderSide(
color: AppColors.cardBorder,
width: 0.2,
),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: size.height * 0.1),
Text(
title,
style: AppStyles.bodyTextStyle2().copyWith(fontSize: 20),
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Text(
textAlign: TextAlign.center,
errorMessage,
style: AppStyles.bodyTextStyle3(),
),
),
if (refreshFunction != null)
TextButton(
onPressed: () {
refreshFunction!();
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.refresh_rounded,
color: AppColors.white,
),
const SizedBox(width: 7),
Text(
textAlign: TextAlign.center,
'Retry',
style:
AppStyles.bodyTextStyle3().copyWith(fontSize: 25),
),
],
),
),
],
),
),
Positioned(
bottom: size.height * 0.165,
child: Lottie.asset(
AppImages.emptyMan,
height: size.height * 0.35,
width: size.width * 0.6,
),
),
],
);
}
}
6 changes: 4 additions & 2 deletions lib/features/cart_page/cubit/cart_page_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:bloc/bloc.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'dart:convert';
import 'dart:developer';

import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';

import '../../../constants/models/cart_model.dart';
import '../../../constants/urls.dart';

Expand Down
10 changes: 6 additions & 4 deletions lib/features/cart_page/ui/cart_page_final.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lottie/lottie.dart';
import 'package:pulzion23/constants/widgets/error_dialog.dart';
import 'package:pulzion23/features/cart_page/ui/widgets/cart_page_content.dart';
import '../../../constants/widgets/empty_page.dart';
import '../../../constants/widgets/error_dialog.dart';
import 'widgets/cart_page_content.dart';

import '../../../constants/images.dart';
import '../../login_page/cubit/check_login_cubit.dart';
Expand Down Expand Up @@ -48,11 +49,12 @@ class CartPageFinal extends StatelessWidget {
);
} else if (state is CartEmpty) {
return Center(
child: ErrorDialog(
'Cart is Empty',
child: EmptyPage(
errorMessage: 'Add some events to your Cart',
refreshFunction: () {
BlocProvider.of<CartPageCubit>(context).loadCart();
},
title: 'Your Cart is Empty',
),
);
} else if (state is CartPageLoaded) {
Expand Down
1 change: 1 addition & 0 deletions lib/features/cart_page/ui/widgets/cart_list_tile.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../constants/colors.dart';
import '../../../../constants/models/cart_model.dart';
import '../../../../constants/styles.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/features/cart_page/ui/widgets/cart_page_content.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
import 'package:pulzion23/constants/images.dart';

import '../../../../constants/images.dart';
import '../../../../constants/models/cart_model.dart';
import '../../../../constants/styles.dart';
import 'cart_list_tile.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/features/compulsory_update/ui/compulsary_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
import 'package:panorama/panorama.dart';
import '../../login_page/ui/widgets/roundedbutton.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../../constants/images.dart';
import '../../../constants/styles.dart';
import '../../../constants/urls.dart';
import '../../login_page/ui/widgets/roundedbutton.dart';

class CompulsoryUpdatePage extends StatelessWidget {
const CompulsoryUpdatePage({super.key});
Expand Down
32 changes: 21 additions & 11 deletions lib/features/event_description/ui/event_description.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import "package:share_plus/share_plus.dart";
import '../../../constants/urls.dart';
import 'package:pulzion23/features/cart_page/cubit/cart_page_cubit.dart';
import 'package:pulzion23/features/event_description/ui/widgets/button.dart';
import '../../cart_page/cubit/cart_page_cubit.dart';
import 'widgets/button.dart';
import '../../../config/size_config.dart';
import '../../../constants/models/event_model.dart';

Expand All @@ -22,8 +22,10 @@ class EventDescription extends StatefulWidget {
State<EventDescription> createState() => _EventDescriptionState();
}

class _EventDescriptionState extends State<EventDescription> with TickerProviderStateMixin {
late final TabController tabBarController = TabController(length: 3, vsync: this);
class _EventDescriptionState extends State<EventDescription>
with TickerProviderStateMixin {
late final TabController tabBarController =
TabController(length: 3, vsync: this);

@override
void dispose() {
Expand Down Expand Up @@ -88,7 +90,8 @@ class _EventDescriptionState extends State<EventDescription> with TickerProvider
Expanded(
child: BlocBuilder<CheckLoginCubit, CheckLoginState>(
builder: (context, state) {
if (state is CheckLoginFailure || state is CheckLoginLoading) {
if (state is CheckLoginFailure ||
state is CheckLoginLoading) {
return event.price == 0
? EventDescriptionPageButton(
'Register Now',
Expand All @@ -98,7 +101,8 @@ class _EventDescriptionState extends State<EventDescription> with TickerProvider
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginSignUpIntro(),
builder: (context) =>
const LoginSignUpIntro(),
),
);
},
Expand All @@ -110,7 +114,8 @@ class _EventDescriptionState extends State<EventDescription> with TickerProvider
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginSignUpIntro(),
builder: (context) =>
const LoginSignUpIntro(),
),
);
},
Expand All @@ -123,6 +128,7 @@ class _EventDescriptionState extends State<EventDescription> with TickerProvider
'Register Now',
Icons.edit_rounded,
() {
// TODO: Call API for registration 0 money
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Registered Successfully'),
Expand All @@ -135,7 +141,8 @@ class _EventDescriptionState extends State<EventDescription> with TickerProvider
'Add to Cart',
Icons.shopping_cart,
() {
BlocProvider.of<CartPageCubit>(context).addCartItem(event.id!);
BlocProvider.of<CartPageCubit>(context)
.addCartItem(event.id!);
},
),
);
Expand Down Expand Up @@ -245,7 +252,8 @@ class _EventDescriptionState extends State<EventDescription> with TickerProvider
Share.share(
'${event.description}\n\nPulzion 23 App: ${EndPoints.playStoreURL}',
subject: 'Pulzion 2023',
sharePositionOrigin: Rect.fromLTWH(0, 0, 10, 10),
sharePositionOrigin:
const Rect.fromLTWH(0, 0, 10, 10),
);
}),
child: const Icon(
Expand Down Expand Up @@ -274,7 +282,8 @@ class _EventDescriptionState extends State<EventDescription> with TickerProvider
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: AppColors.eventCardGradientList.elementAt(
event.id! % AppColors.eventCardGradientList.length,
event.id! %
AppColors.eventCardGradientList.length,
),
),
),
Expand Down Expand Up @@ -322,7 +331,8 @@ class _EventDescriptionState extends State<EventDescription> with TickerProvider
),
),
),
unselectedLabelColor: AppColors.cardSubtitleTextColor,
unselectedLabelColor:
AppColors.cardSubtitleTextColor,
labelColor: AppColors.loginPageAccent,
tabs: const [
Text(
Expand Down
7 changes: 5 additions & 2 deletions lib/features/event_description/ui/widgets/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ class EventDescriptionPageButton extends StatelessWidget {
final IconData buttonIcon;
final Function onPressed;
const EventDescriptionPageButton(
this.buttonText, this.buttonIcon, this.onPressed,
{super.key,});
this.buttonText,
this.buttonIcon,
this.onPressed, {
super.key,
});

@override
Widget build(BuildContext context) {
Expand Down
6 changes: 3 additions & 3 deletions lib/features/event_slots/ui/booked_main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../event_slots/logic/booked_slot_cubit.dart';

import './booked_window.dart';
import './not_booked_window.dart';
import '../../event_slots/logic/booked_slot_cubit.dart';
import 'booked_window.dart';
import 'not_booked_window.dart';

class EventBookingPage extends StatelessWidget {
static const routeName = '/event-page';
Expand Down

0 comments on commit 9ef643a

Please sign in to comment.