Skip to content

Commit

Permalink
feat: evently provider
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanRns committed May 8, 2024
1 parent 1e076c7 commit a8ac51a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 74 deletions.
9 changes: 3 additions & 6 deletions evently/lib/evently_provider.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@



import 'package:evently/models/denom.dart';
import 'package:flutter/cupertino.dart';
import 'package:injectable/injectable.dart';

enum FreeDrop { yes, no, unselected }

@lazySingleton
class EventlyProvider extends ChangeNotifier {

Denom _selectedDenom = Denom.availableDenoms.first;

Denom get selectedDenom => _selectedDenom;
Expand All @@ -22,5 +20,4 @@ class EventlyProvider extends ChangeNotifier {
_selectedDenom = value;
notifyListeners();
}

}
}
52 changes: 29 additions & 23 deletions evently/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:ui';
import 'package:easy_localization/easy_localization.dart';
import 'package:evently/evently_provider.dart';
import 'package:evently/screens/create_event.dart';
import 'package:evently/screens/event_hub/event_hub_screen.dart';
import 'package:evently/screens/splash_screen.dart';
Expand All @@ -9,7 +10,7 @@ import 'package:evently/utils/evently_app_theme.dart';
import 'package:evently/utils/route_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:provider/provider.dart';

bool isTablet = false;

Expand Down Expand Up @@ -45,28 +46,33 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
minTextAdapt: true,
builder: (BuildContext context, child) => MaterialApp(
builder: (context, widget) {
ScreenUtil.init(context);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
child: widget!,
);
},
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
title: 'Evently',
navigatorKey: navigatorKey,
theme: EventlyAppTheme.theme(context),
initialRoute: '/',
routes: {
'/': (context) => const SplashScreen(),
RouteUtil.kRouteEventHub: (context) => const EventHubScreen(),
RouteUtil.createEvent: (context) => const CreateEvent(),
},
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => sl<EventlyProvider>()),
],
child: ScreenUtilInit(
minTextAdapt: true,
builder: (BuildContext context, child) => MaterialApp(
builder: (context, widget) {
ScreenUtil.init(context);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
child: widget!,
);
},
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
title: 'Evently',
navigatorKey: navigatorKey,
theme: EventlyAppTheme.theme(context),
initialRoute: '/',
routes: {
'/': (context) => const SplashScreen(),
RouteUtil.kRouteEventHub: (context) => const EventHubScreen(),
RouteUtil.createEvent: (context) => const CreateEvent(),
},
),
),
);
}
Expand Down
52 changes: 7 additions & 45 deletions evently/lib/screens/price_screen.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@

import 'package:easy_localization/easy_localization.dart';
import 'package:evently/evently_provider.dart';
import 'package:evently/screens/custom_widgets/step_labels.dart';
import 'package:evently/screens/custom_widgets/steps_indicator.dart';
import 'package:evently/utils/amount_formatter.dart';
import 'package:evently/utils/constants.dart';
import 'package:evently/utils/evently_app_theme.dart';
import 'package:evently/utils/screen_responsive.dart';
import 'package:evently/utils/space_utils.dart';
import 'package:evently/viewmodels/create_event_viewmodel.dart';
import 'package:evently/widgets/clipped_button.dart';
import 'package:evently/widgets/evently_price_input_field.dart';
import 'package:evently/widgets/evently_text_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';

import '../generated/locale_keys.g.dart';

class PriceScreen extends StatefulWidget {
const PriceScreen({Key? key}) : super(key: key);
const PriceScreen({super.key});

@override
State<PriceScreen> createState() => _PriceScreenState();
}

class _PriceScreenState extends State<PriceScreen> {
final _formKey = GlobalKey<FormState>();
final ValueNotifier<String> _priceFieldError = ValueNotifier("");


@override
void dispose() {
Expand Down Expand Up @@ -133,9 +129,7 @@ class _PriceScreenState extends State<PriceScreen> {
width: 30.w,
),
InkWell(
onTap: () {

},
onTap: () {},
child: Container(
width: 140.w,
height: 30.h,
Expand Down Expand Up @@ -168,17 +162,15 @@ class _PriceScreenState extends State<PriceScreen> {
inputFormatters: [FilteringTextInputFormatter.digitsOnly, LengthLimitingTextInputFormatter(kMaxPriceLength), provider.selectedDenom.getFormatter()],
controller: provider.priceController,
validator: (value) {

return null;
},
),

Text(
LocaleKeys.network_fee_listed_price_occur_on_chain.tr(),
style: TextStyle(color: EventlyAppTheme.kLightPurple, fontSize: 14.sp, fontWeight: FontWeight.w800),
),
],
),

],
),
if (provider.isFreeDrop == FreeDrop.unselected)
Expand All @@ -199,7 +191,6 @@ class _PriceScreenState extends State<PriceScreen> {
onPressed: () async {
if (provider.isFreeDrop != FreeDrop.unselected) {
FocusScope.of(context).unfocus();
validateAndUpdatePrice(moveNextPage: true);
}
},
cuttingHeight: 15.h,
Expand All @@ -210,18 +201,10 @@ class _PriceScreenState extends State<PriceScreen> {
VerticalSpace(10.h),
Center(
child: InkWell(

onTap: () {
if (provider.isFreeDrop == FreeDrop.unselected) {
Navigator.pop(context);
return;
}
FocusScope.of(context).unfocus();
validateAndUpdatePrice(moveNextPage: false);
},
onTap: () {},
child: Text(
LocaleKeys.save_as_draft.tr(),
style: TextStyle(color: EaselAppTheme.kLightGreyText, fontSize: 14.sp, fontWeight: FontWeight.w700),
LocaleKeys.save_draft.tr(),
style: TextStyle(color: EventlyAppTheme.kLightGreyText, fontSize: 14.sp, fontWeight: FontWeight.w700),
),
),
),
Expand All @@ -236,25 +219,4 @@ class _PriceScreenState extends State<PriceScreen> {
),
);
}

Future<void> validateAndUpdatePrice({required bool moveNextPage}) async {
final navigator = Navigator.of(context);
final HomeViewModel homeViewModel = context.read<HomeViewModel>();

if (!_formKey.currentState!.validate()) {
return;
}
GetIt.I.get<CreatorHubViewModel>().changeSelectedCollection(CollectionType.draft);

if (context.read<EaselProvider>().isFreeDrop == FreeDrop.yes) {
if (_royaltiesFieldError.value.isNotEmpty || _noOfEditionsFieldError.value.isNotEmpty) return;
await context.read<EaselProvider>().updateNftFromPrice(nft!.id!);
moveNextPage ? homeViewModel.nextPage() : navigator.pop();

return;
}
if (_royaltiesFieldError.value.isNotEmpty || _noOfEditionsFieldError.value.isNotEmpty || _priceFieldError.value.isNotEmpty) return;
await context.read<EaselProvider>().updateNftFromPrice(nft!.id!);
moveNextPage ? homeViewModel.nextPage() : navigator.pop();
}
}
2 changes: 2 additions & 0 deletions evently/lib/utils/di/di.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a8ac51a

Please sign in to comment.