diff --git a/README.md b/README.md index c3ef16e..ce70fd9 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,3 @@ -# mop +# 凡泰极客小程序 Flutter 插件 -A new flutter plugin project. - -## Getting Started - -This project is a starting point for a Flutter -[plug-in package](https://flutter.dev/developing-packages/), -a specialized package that includes platform-specific implementation code for -Android and/or iOS. - -For help getting started with Flutter, view our -[online documentation](https://flutter.dev/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. +本插件提供在 Flutter 运行环境中运行小程序能力。 diff --git a/android/build.gradle b/android/build.gradle index 4140b5d..5aded18 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -13,10 +13,10 @@ buildscript { google() jcenter() maven { - url "https://gradle.finogeeks.club/repository/finogeeks/" + url "https://gradle.finogeeks.club/repository/applet/" credentials { - username "xiaoyu" - password "xy123456" + username "applet" + password "123321" } } maven { url "https://jitpack.io" } @@ -35,10 +35,10 @@ rootProject.allprojects { google() jcenter() maven { - url "https://gradle.finogeeks.club/repository/finogeeks/" + url "https://gradle.finogeeks.club/repository/applet/" credentials { - username "xiaoyu" - password "xy123456" + username "applet" + password "123321" } } maven { url "https://jitpack.io" } @@ -77,7 +77,6 @@ kapt { } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.finogeeks.lib:finapplet:2.0.51' - implementation 'org.greenrobot:greendao:3.2.2' + implementation 'com.finogeeks.lib:finapplet:2.0.75' } diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java index 8993079..c2d099e 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java @@ -29,7 +29,6 @@ public class AppletModule extends BaseApi { @Override public void invoke(String event, Map param, ICallback callback) { - System.out.println("AppletModule"); if (param.get("appId") == null) { callback.onFail(new HashMap(){ { diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java index 126fde9..989190c 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java @@ -46,6 +46,9 @@ public class BaseModule extends BaseApi { } if (param.get("apiPrefix") != null) { apiPrefix = String.valueOf(param.get("apiPrefix")); + if (!apiPrefix.endsWith("/")) { + apiPrefix = apiPrefix + "/"; + } } FinAppConfig config = new FinAppConfig.Builder() .setAppKey(appkey) diff --git a/example/lib/main.dart b/example/lib/main.dart index d0eba71..d94fef6 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'dart:async'; - -import 'package:flutter/services.dart'; +import 'dart:io'; import 'package:mop/mop.dart'; void main() => runApp(MyApp()); @@ -15,27 +14,22 @@ class _MyAppState extends State { @override void initState() { super.initState(); - initPlatformState(); + init(); } // Platform messages are asynchronous, so we initialize in an async method. - Future initPlatformState() async { - // String platformVersion; - // // Platform messages may fail, so we use a try/catch PlatformException. - // try { - // platformVersion = await Mop.instance.platformVersion; - // print(platformVersion); - // } on PlatformException { - // platformVersion = 'Failed to get platform version.'; - // } - final res = await Mop.instance.initialize( - '22LyZEib0gLTQdU3MUauARjmmp6QmYgjGb3uHueys1oA', '98c49f97a031b555', - apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/'); - print(res); - - // 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. + Future init() async { + if (Platform.isIOS) { + final res = await Mop.instance.initialize( + '22LyZEib0gLTQdU3MUauARlLry7JL/2fRpscC9kpGZQA', '1c11d7252c53e0b6', + apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/mop'); + print(res); + } else if (Platform.isAndroid) { + final res = await Mop.instance.initialize( + '22LyZEib0gLTQdU3MUauARjmmp6QmYgjGb3uHueys1oA', '98c49f97a031b555', + apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/mop'); + print(res); + } if (!mounted) return; } @@ -44,20 +38,60 @@ class _MyAppState extends State { return MaterialApp( home: Scaffold( appBar: AppBar( - title: const Text('Plugin example app'), + title: const Text('凡泰极客小程序 Flutter 插件'), ), body: Center( - child: FlatButton( - onPressed: () { - // appId: '5e3c147a188211000141e9b1', - // path: "/pages/index/index", - // query: "key1=value1&key2=value2", - // scene: "1001" - Mop.instance.openApplet('5e3c147a188211000141e9b1', - path: '/pages/index/index', query: 'key1=value1&key2=value2'); - }, - child: Text('打开小程序'), - )), + child: Container( + padding: EdgeInsets.only( + top: 20, + ), + child: Column( + children: [ + Container( + 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('5e3c147a188211000141e9b1'); + }, + child: Text( + '打开示例小程序', + style: TextStyle(color: Colors.white), + ), + ), + ), + SizedBox(height: 30), + Container( + 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('5e4d123647edd60001055df1'); + }, + child: Text( + '打开官方小程序', + style: TextStyle(color: Colors.white), + ), + ), + ), + ], + ), + ), + ), ), ); } diff --git a/lib/mop.dart b/lib/mop.dart index 2d287b3..b32f247 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -65,16 +65,15 @@ class Mop { /// [appId] is required. /// [path] is miniprogram open path. example /pages/index/index /// [query] is miniprogram query parameters. example key1=value1&key2=value2 - /// [scene] is miniprogram scene string. example 1100 /// /// Future openApplet(final String appId, - {final String path, final String query, final String scene}) async { + {final String path, final String query}) async { Map params; if (path != '') { params = { 'appId': appId, - 'params': {'path': path, 'query': query, 'scene': scene} + 'params': {'path': path, 'query': query} }; } else { params = {'appId': appId};