xdja_bridge 0.0.6 copy "xdja_bridge: ^0.0.6" to clipboard
xdja_bridge: ^0.0.6 copied to clipboard

XDJA flutter plugin.

example/lib/main.dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xdja_bridge/xdja_bridge.dart';

void main() {
  runApp(ExampleApp());
}

class ExampleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'plugin example',
      home: Scaffold(
        appBar: AppBar(
          title: Text('plugin example'),
        ),
        body: MyApp(),
      ),
    );
  }
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _token = 'Unknown';
  String _safeCardId = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
    getUaacToken();
    getSafeCardId();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Bridge.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // 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(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> getUaacToken() async {
    String token;
    try {
      token = await Bridge.uaacToken;
    } on PlatformException catch (e, s) {
      token = e.message;
      print('Stack trace:\n $s');
    }
    setState(() {
      _token = token;
    });
  }

  Future<void> getSafeCardId() async {
    String safeCardId;
    try {
      safeCardId = await Bridge.safeCardId;
    } on PlatformException catch (e, s) {
      safeCardId = e.message;
      print('Stack trace:\n $s');
    }
    setState(() {
      _safeCardId = safeCardId;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            'Running on: $_platformVersion\n',
          ),
          Text(
            'token: $_token',
            maxLines: 3,
          ),
          Text(
            'SafeCardId: $_safeCardId',
          ),
        ],
      ),
    );
  }

}
0
likes
30
pub points
0%
popularity

Publisher

verified publisherxiaoyang.pro

XDJA flutter plugin.

Homepage

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on xdja_bridge