-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing logic & working example for app
- Loading branch information
Showing
12 changed files
with
709 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
), | ||
], | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
example/lib/app/features/main/providers/main_providers.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
Oops, something went wrong.