diff --git a/example/lib/main.dart b/example/lib/main.dart index dd67e41..b488f98 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,124 +1,124 @@ -// import 'package:flutter/material.dart'; -// import 'dart:async'; -// import 'dart:io'; -// import 'package:mop/mop.dart'; +import 'package:flutter/material.dart'; +import 'dart:async'; +import 'dart:io'; +import 'package:mop/mop.dart'; -// void main() => runApp(MyApp()); +void main() => runApp(MyApp()); -// class MyApp extends StatefulWidget { -// @override -// _MyAppState createState() => _MyAppState(); -// } +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} -// class _MyAppState extends State { -// @override -// void initState() { -// super.initState(); -// init(); -// } +class _MyAppState extends State { + @override + void initState() { + super.initState(); + init(); + } -// // Platform messages are asynchronous, so we initialize in an async method. -// Future init() async { -// if (Platform.isIOS) { -// final res = await Mop.instance.initialize( -// '22LyZEib0gLTQdU3MUauAZ0pZVbKTWGmNN6Lx8hXhIkA', '74bde5fad53a817c', -// apiServer: 'https://api.finclip.com', apiPrefix: '/api/v1/mop'); -// print(res); -// } else if (Platform.isAndroid) { -// final res = await Mop.instance.initialize( -// '22LyZEib0gLTQdU3MUauAZ0pZVbKTWGmNN6Lx8hXhIkA', '74bde5fad53a817c', -// apiServer: 'https://api.finclip.com', apiPrefix: '/api/v1/mop'); -// print(res); -// } -// if (!mounted) return; -// } + // Platform messages are asynchronous, so we initialize in an async method. + Future init() async { + if (Platform.isIOS) { + final res = await Mop.instance.initialize( + '22LyZEib0gLTQdU3MUauAZ0pZVbKTWGmNN6Lx8hXhIkA', '74bde5fad53a817c', + apiServer: 'https://api.finclip.com', apiPrefix: '/api/v1/mop'); + print(res); + } else if (Platform.isAndroid) { + final res = await Mop.instance.initialize( + '22LyZEib0gLTQdU3MUauAZ0pZVbKTWGmNN6Lx8hXhIkA', '74bde5fad53a817c', + apiServer: 'https://api.finclip.com', apiPrefix: '/api/v1/mop'); + print(res); + } + if (!mounted) return; + } -// // 5e637a18cbfae4000170fa7a -// @override -// Widget build(BuildContext context) { -// return MaterialApp( -// home: Scaffold( -// appBar: AppBar( -// title: const Text('凡泰极客小程序 Flutter 插件'), -// ), -// body: Center( -// child: Container( -// padding: EdgeInsets.only( -// top: 20, -// ), -// child: Column( -// children: [ -// Container( -// width: 140, -// decoration: BoxDecoration( -// borderRadius: BorderRadius.all(Radius.circular(5)), -// gradient: LinearGradient( -// colors: const [Color(0xFF12767e), Color(0xFF0dabb8)], -// stops: const [0.0, 1.0], -// begin: Alignment.topCenter, -// end: Alignment.bottomCenter, -// ), -// ), -// child: FlatButton( -// onPressed: () { -// Mop.instance.openApplet('5ea03fa563cb900001d73863', -// path: 'pages/index/index', query: ''); -// }, -// child: Text( -// '打开画图小程序', -// style: TextStyle(color: Colors.white), -// ), -// ), -// ), -// SizedBox(height: 30), -// Container( -// width: 140, -// decoration: BoxDecoration( -// borderRadius: BorderRadius.all(Radius.circular(5)), -// gradient: LinearGradient( -// colors: const [Color(0xFF12767e), Color(0xFF0dabb8)], -// stops: const [0.0, 1.0], -// begin: Alignment.topCenter, -// end: Alignment.bottomCenter, -// ), -// ), -// child: FlatButton( -// onPressed: () { -// Mop.instance.openApplet('5ea0401463cb900001d73865'); -// }, -// child: Text( -// '打开官方小程序', -// style: TextStyle(color: Colors.white), -// ), -// ), -// ), -// SizedBox(height: 30), -// Container( -// width: 140, -// decoration: BoxDecoration( -// borderRadius: BorderRadius.all(Radius.circular(5)), -// gradient: LinearGradient( -// colors: const [Color(0xFF12767e), Color(0xFF0dabb8)], -// stops: const [0.0, 1.0], -// begin: Alignment.topCenter, -// end: Alignment.bottomCenter, -// ), -// ), -// child: FlatButton( -// onPressed: () { -// Mop.instance.openApplet('5ea0412663cb900001d73867'); -// }, -// child: Text( -// '我的对账单', -// style: TextStyle(color: Colors.white), -// ), -// ), -// ), -// ], -// ), -// ), -// ), -// ), -// ); -// } -// } + // 5e637a18cbfae4000170fa7a + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('凡泰极客小程序 Flutter 插件'), + ), + body: Center( + child: Container( + padding: EdgeInsets.only( + top: 20, + ), + child: Column( + children: [ + Container( + width: 140, + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(5)), + gradient: LinearGradient( + colors: const [Color(0xFF12767e), Color(0xFF0dabb8)], + stops: const [0.0, 1.0], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + ), + ), + child: FlatButton( + onPressed: () { + Mop.instance.openApplet('5ea03fa563cb900001d73863', + path: 'pages/index/index', query: ''); + }, + child: Text( + '打开画图小程序', + style: TextStyle(color: Colors.white), + ), + ), + ), + SizedBox(height: 30), + Container( + width: 140, + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(5)), + gradient: LinearGradient( + colors: const [Color(0xFF12767e), Color(0xFF0dabb8)], + stops: const [0.0, 1.0], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + ), + ), + child: FlatButton( + onPressed: () { + Mop.instance.openApplet('5ea0401463cb900001d73865'); + }, + child: Text( + '打开官方小程序', + style: TextStyle(color: Colors.white), + ), + ), + ), + SizedBox(height: 30), + Container( + width: 140, + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(5)), + gradient: LinearGradient( + colors: const [Color(0xFF12767e), Color(0xFF0dabb8)], + stops: const [0.0, 1.0], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + ), + ), + child: FlatButton( + onPressed: () { + Mop.instance.openApplet('5ea0412663cb900001d73867'); + }, + child: Text( + '我的对账单', + style: TextStyle(color: Colors.white), + ), + ), + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index e7b7478..bf7d60e 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -1,27 +1,27 @@ -// // This is a basic Flutter widget test. -// // -// // To perform an interaction with a widget in your test, use the WidgetTester -// // utility that Flutter provides. For example, you can send tap and scroll -// // gestures. You can also use WidgetTester to find child widgets in the widget -// // tree, read text, and verify that the values of widget properties are correct. +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility that Flutter provides. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. -// import 'package:flutter/material.dart'; -// import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; -// import 'package:mop_example/main.dart'; +import 'package:mop_example/main.dart'; -// void main() { -// testWidgets('Verify Platform version', (WidgetTester tester) async { -// // Build our app and trigger a frame. -// await tester.pumpWidget(MyApp()); +void main() { + testWidgets('Verify Platform version', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(MyApp()); -// // Verify that platform version is retrieved. -// expect( -// find.byWidgetPredicate( -// (Widget widget) => widget is Text && -// widget.data.startsWith('Running on:'), -// ), -// findsOneWidget, -// ); -// }); -// } + // Verify that platform version is retrieved. + expect( + find.byWidgetPredicate( + (Widget widget) => widget is Text && + widget.data!.startsWith('Running on:'), + ), + findsOneWidget, + ); + }); +} diff --git a/lib/mop.dart b/lib/mop.dart index feeef6d..43aa802 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -70,11 +70,11 @@ class Mop { /// [disablePermission] is optional. /// Future initialize(String appkey, String secret, - {required String apiServer, - required String apiPrefix, - required String cryptType, - required bool disablePermission, - required String userId, + { String? apiServer, + String? apiPrefix, + String? cryptType, + bool? disablePermission, + String? userId, bool encryptServerData = false, bool debug = false}) async { final Map ret = await _channel.invokeMethod('initialize', { @@ -103,26 +103,26 @@ class Mop { /// [cryptType] is optional. cryptType, should be MD5/SM Future openApplet( final String appId, { - required final String path, - required final String query, - required final int sequence, - required final String apiServer, - required final String apiPrefix, - required final String fingerprint, - required final String cryptType, - required final String scene, + final String? path, + final String? query, + final int? sequence, + final String? apiServer, + final String? apiPrefix, + final String? fingerprint, + final String? cryptType, + final String? scene, }) async { Map params = {'appId': appId}; Map param = {}; param["path"] = path; param["query"] = query; if (param.length > 0) params["params"] = param; - params["sequence"] = sequence; - params["apiServer"] = apiServer; - params["apiPrefix"] = apiPrefix; - params["fingerprint"] = fingerprint; - params["cryptType"] = cryptType; - param["scene"] = scene; + if (sequence != null) params["sequence"] = sequence; + if (apiServer != null) params["apiServer"] = apiServer; + if (apiPrefix != null) params["apiPrefix"] = apiPrefix; + if (fingerprint != null) params["fingerprint"] = fingerprint; + if (cryptType != null) params["cryptType"] = cryptType; + if (scene != null) param["scene"] = scene; final Map ret = await _channel.invokeMethod('openApplet', params); return ret; }