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

outdated

XDJA flutter plugin.

example/lib/main.dart

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

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;
    });
  }

Future<String> socketRequest() async {
    String response;
    String request = '''<?xml version="1.0" encoding="UTF-8"?><Root><ReqType>req_jtgl_zdgx</ReqType><SessionID>0093330900288442470</SessionID><BeginNo>1</BeginNo><DataSource>1</DataSource><Condition><c_dbname>jtglzd.db</c_dbname><c_date Type='1' Relation='9'>20200831235914</c_date></Condition></Root>''';
    try {
      print('request:$request');
      response = await Bridge.gprsServerRequest("192.168.20.152", "2003", request);
      print('response:$response');
      return response;
    } on PlatformException catch (e, s) {
      print('Stack trace:\n $s');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          RaisedButton(onPressed: () async{
            String response = await socketRequest();
            print('qq:$response');
          }, child: Text('test')),
          Text(
            'Running on: $_platformVersion\n',
          ),
          Text(
            'token: $_token',
            maxLines: 3,
          ),
          Text(
            'SafeCardId: $_safeCardId',
          ),
        ],
      ),
    );
  }
}
0
likes
0
points
29
downloads

Publisher

verified publisherxiaoyang.pro

Weekly Downloads

XDJA flutter plugin.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on xdja_bridge

Packages that implement xdja_bridge