Skip to content

Commit 0089958

Browse files
committed
added the comment on the example code and modified the some of unused code
1 parent 61ccb36 commit 0089958

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

example/lib/main.dart

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class MyApp extends StatelessWidget {
2525
}
2626
}
2727

28+
/// paymentType: payWithAgreement, payWithoutAgreement, createAgreement
29+
/// enum values: as per your requirement
2830
enum PaymentType { payWithAgreement, payWithoutAgreement, createAgreement }
2931

3032
class HomePage extends StatefulWidget {
@@ -175,30 +177,47 @@ class HomePageState extends State<HomePage> {
175177
setState(() {
176178
isLoading = true;
177179
});
180+
181+
/// create an instance of FlutterBkash
178182
final flutterBkash = FlutterBkash();
179183

184+
/// if the payment type is createAgreement
180185
if (_paymentType == PaymentType.createAgreement) {
181186
try {
182187
// remove focus from TextField to hide keyboard
183188
FocusManager.instance.primaryFocus?.unfocus();
189+
190+
/// call createAgreement method to create an agreement as parameter pass the context
184191
final result = await flutterBkash
185192
.createAgreement(context: context);
193+
194+
/// show the log
186195
dev.log(result.toString());
196+
197+
/// show the snack-bar
187198
_showSnackbar(
188199
"(Success) AgreementId: ${result.agreementId}");
189200
} on BkashFailure catch (e, st) {
201+
/// if any error occurred then show the log
190202
dev.log(e.message, error: e, stackTrace: st);
203+
204+
/// show the snack-bar
191205
_showSnackbar(e.message);
192206
} catch (e, st) {
207+
/// if any error occurred then show the log
193208
dev.log("Something went wrong",
194209
error: e, stackTrace: st);
210+
211+
/// show the snack-bar
195212
_showSnackbar("Something went wrong");
196213
}
197214
setState(() {
198215
isLoading = false;
199216
});
200217
return;
201218
}
219+
220+
/// if the payment type is payWithoutAgreement
202221
if (_paymentType ==
203222
PaymentType.payWithoutAgreement) {
204223
final amount = _amountController.text.trim();
@@ -214,39 +233,55 @@ class HomePageState extends State<HomePage> {
214233
});
215234
return;
216235
}
217-
// remove focus from TextField to hide keyboard
236+
237+
/// remove focus from TextField to hide keyboard
218238
FocusManager.instance.primaryFocus?.unfocus();
219-
// Goto BkashPayment page & pass the params
220239

240+
/// Goto BkashPayment page & pass the params
221241
try {
242+
/// call pay method to pay without agreement as parameter pass the context, amount, merchantInvoiceNumber
222243
final result = await flutterBkash.pay(
223244
context: context,
224-
amount: double.parse(
225-
amount), // need it double type
245+
// need the context as BuildContext
246+
amount: double.parse(amount),
247+
// need it double type
226248
merchantInvoiceNumber: "tranId",
227249
);
228250

251+
/// if the payment is success then show the log
229252
dev.log(result.toString());
253+
254+
/// if the payment is success then show the snack-bar
230255
_showSnackbar(
231256
"(Success) tranId: ${result.trxId}");
232257
} on BkashFailure catch (e, st) {
258+
/// if something went wrong then show the log
233259
dev.log(e.message, error: e, stackTrace: st);
260+
261+
/// if something went wrong then show the snack-bar
234262
_showSnackbar(e.message);
235263
} catch (e, st) {
264+
/// if something went wrong then show the log
236265
dev.log("Something went wrong",
237266
error: e, stackTrace: st);
267+
268+
/// if something went wrong then show the snack-bar
238269
_showSnackbar("Something went wrong");
239270
}
240271
setState(() {
241272
isLoading = false;
242273
});
243274
return;
244275
}
276+
277+
/// if the payment type is payWithAgreement
245278
if (_paymentType == PaymentType.payWithAgreement) {
279+
/// amount & agreementId is required
246280
final amount = _amountController.text.trim();
247281
final agreementId =
248282
_agreementIdController.text.trim();
249283

284+
/// if the amount is empty then show the snack-bar
250285
if (amount.isEmpty) {
251286
// if the amount is empty then show the snack-bar
252287
ScaffoldMessenger.of(context).showSnackBar(
@@ -259,6 +294,7 @@ class HomePageState extends State<HomePage> {
259294
return;
260295
}
261296

297+
/// is the agreementId is empty then show the snack-bar
262298
if (agreementId.isEmpty) {
263299
// if the agreementId is empty then show the snack-bar
264300
ScaffoldMessenger.of(context).showSnackBar(
@@ -271,11 +307,12 @@ class HomePageState extends State<HomePage> {
271307
return;
272308
}
273309

274-
// remove focus from TextField to hide keyboard
310+
/// remove focus from TextField to hide keyboard
275311
FocusManager.instance.primaryFocus?.unfocus();
276312

277313
// Goto BkashPayment page & pass the params
278314
try {
315+
/// call payWithAgreement method to pay with agreement as parameter pass the context, amount, agreementId, marchentInvoiceNumber
279316
final result =
280317
await flutterBkash.payWithAgreement(
281318
context: context,
@@ -285,15 +322,22 @@ class HomePageState extends State<HomePage> {
285322
"merchantInvoiceNumber",
286323
);
287324

325+
/// print the result
288326
dev.log(result.toString());
327+
328+
/// show the snack-bar with success message
289329
_showSnackbar(
290330
"(Success) tranId: ${result.trxId}");
291331
} on BkashFailure catch (e, st) {
332+
/// print the error message & stackTrace
292333
dev.log(e.message, error: e, stackTrace: st);
293334
_showSnackbar(e.message);
294335
} catch (e, st) {
336+
/// print the error message & stackTrace
295337
dev.log("Something went wrong",
296338
error: e, stackTrace: st);
339+
340+
/// show the snack-bar with error message
297341
_showSnackbar("Something went wrong");
298342
}
299343
setState(() {
@@ -312,6 +356,7 @@ class HomePageState extends State<HomePage> {
312356
);
313357
}
314358

359+
/// show snack-bar with message
315360
void _showSnackbar(String message) => ScaffoldMessenger.of(context)
316361
..hideCurrentSnackBar()
317362
..showSnackBar(SnackBar(content: Text(message)));

example/test/widget_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import 'package:flutter/material.dart';
99
import 'package:flutter_test/flutter_test.dart';
1010

11-
import 'package:example/main.dart';
11+
import '../lib/main.dart';
1212

1313
void main() {
1414
testWidgets('Counter increments smoke test', (WidgetTester tester) async {

0 commit comments

Comments
 (0)