Skip to content

Commit

Permalink
implementing logic & working example for app
Browse files Browse the repository at this point in the history
  • Loading branch information
GJJ2019 committed Jul 9, 2022
1 parent 7c615cb commit 541cbc9
Show file tree
Hide file tree
Showing 12 changed files with 709 additions and 97 deletions.
25 changes: 25 additions & 0 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'core/router/router.dart';
import 'core/theme/app_theme.dart';

class App extends ConsumerWidget {
/// [App]
const App({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final appTheme = ref.read(appThemeProvider);
final router = ref.read(routerProvider);

return MaterialApp.router(
title: 'Easy Upi Payment',
theme: appTheme.lightTheme,
darkTheme: appTheme.darkTheme,
routeInformationParser: router.routeInformationParser,
routeInformationProvider: router.routeInformationProvider,
routerDelegate: router.routerDelegate,
);
}
}
79 changes: 79 additions & 0 deletions example/lib/app/core/local_storage/app_storage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:hive_flutter/hive_flutter.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class AppStorage {
// ignore: unused_field
Box? _box;

/// for initialling app local storage
Future<void> initAppStorage() async {
await Hive.initFlutter();
// TODO: add your storage name here
_box = await Hive.openBox('hello world');
}

// example of storing & getting value

/// for storing uploaded string value
final String _upiId = 'upiId';

/// for getting string from box
String? getUpiId() {
return _box?.get(_upiId) as String?;
}

/// for storing upiId to app
Future<void> putUpiId(String upiId) async {
await _box?.put(_upiId, upiId);
}

/// for storing uploaded string value
final String _name = 'name';

/// for getting string from box
String? getName() {
return _box?.get(_name) as String?;
}

/// for storing name to app
Future<void> putName(String name) async {
await _box?.put(_name, name);
}

/// for storing uploaded string value
final String _amount = 'amount';

/// for getting string from box
String? getAmount() {
return _box?.get(_amount) as String?;
}

/// for storing upiId to app
Future<void> putAmount(String amount) async {
await _box?.put(_amount, amount);
}

/// for storing uploaded string value
final String _description = 'description';

/// for getting string from box
String? getDescription() {
return _box?.get(_description) as String?;
}

/// for storing upiId to app
Future<void> putDescription(String description) async {
await _box?.put(_description, description);
}

/// for clearing all data in box
Future<void> clearAllData() async {
await _box?.clear();
}
}

final appStorageProvider = Provider<AppStorage>(
(_) {
throw UnimplementedError();
},
);
21 changes: 21 additions & 0 deletions example/lib/app/core/router/router.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../features/main/view/main_view.dart';

///
/// for getting routers that are present in the app
///
final routerProvider = Provider<GoRouter>(
(ref) {
return GoRouter(
initialLocation: MainView.routeName,
routes: [
GoRoute(
path: MainView.routeName,
builder: (context, state) => const MainView(),
),
],
);
},
);
22 changes: 22 additions & 0 deletions example/lib/app/core/theme/app_theme.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class AppTheme {
/// for getting light theme
ThemeData get lightTheme {
return FlexThemeData.light(
scheme: FlexScheme.green,
);
}

/// for getting dark theme
ThemeData get darkTheme {
return FlexThemeData.dark(
scheme: FlexScheme.green,
);
}
}

/// for providing app theme [AppTheme]
final appThemeProvider = Provider<AppTheme>((_) => AppTheme());
38 changes: 38 additions & 0 deletions example/lib/app/features/main/providers/main_providers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:easy_upi_payment/easy_upi_payment.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class MainStateNotifier extends StateNotifier<MainState> {
MainStateNotifier() : super(MainState.initial);

TransactionDetailModel? transactionDetailModel;

/// for starting payment
Future<void> startPayment(EasyUpiPaymentModel model) async {
state = MainState.loading;
try {
//
final res = await EasyUpiPaymentPlatform.instance.startPayment(model);
if (res != null) {
transactionDetailModel = res;
state = MainState.success;
} else {
state = MainState.error;
}
} on EasyUpiPaymentException {
state = MainState.error;
}
}
}

final mainStateProvider = StateNotifierProvider.autoDispose<MainStateNotifier, MainState>(
(ref) {
return MainStateNotifier();
},
);

enum MainState {
initial,
loading,
success,
error,
}
Loading

0 comments on commit 541cbc9

Please sign in to comment.