flutter_play_test 0.0.4 copy "flutter_play_test: ^0.0.4" to clipboard
flutter_play_test: ^0.0.4 copied to clipboard

flutter_play_test Flutter Plugin

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:moneyhash_payment/flutter_test_payment.dart';
void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  FlutterTestPaymentResult? _result;
  TextEditingController? paymentIdTextEditController = TextEditingController(text: "9ep3xXZ");
  String? errorText;

  @override
  void initState() {
    super.initState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    FlutterTestPaymentResult? result;
    try {
      result = await FlutterTestPayment.startPaymentFlow(
          paymentIdTextEditController!.text);
    } on PlatformException {
      // Handle the errors
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _result = result;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Test Example App'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              TextField(
                onChanged: (value) {
                  setState(() {
                    errorText = null;
                  });
                },
                controller: paymentIdTextEditController,
                decoration: InputDecoration(
                    errorText: errorText,
                    border: const OutlineInputBorder(
                        borderRadius: BorderRadius.all(Radius.circular(10)))),
              ),
              const SizedBox(height: 16),
              ElevatedButton(
                onPressed: () {
                  if (paymentIdTextEditController!.text.isNotEmpty) {
                    initPlatformState();
                  } else {
                    setState(() {
                      errorText = "Please enter payment id";
                    });
                  }
                },
                child: const Text("Click"),
              ),
              const SizedBox(height: 32),
              Text(
                  'Payment Status: ${_result?.result?.transaction?.status ?? "no payment status"}\n'),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
110
pub points
0%
popularity

Publisher

unverified uploader

flutter_play_test Flutter Plugin

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_play_test