智莺生活APP的阿里百川 Flutter 插件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

172 lines
6.2 KiB

  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_alibc/alibc_const_key.dart';
  5. import 'package:flutter_alibc/flutter_alibc.dart';
  6. import 'package:flutter_alibc/alibc_model.dart';
  7. void main() => runApp(MyApp());
  8. class MyApp extends StatefulWidget {
  9. @override
  10. _MyAppState createState() => _MyAppState();
  11. }
  12. class _MyAppState extends State<MyApp> {
  13. String _platformVersion = 'Unknown';
  14. @override
  15. void initState() {
  16. super.initState();
  17. // FlutterAlibc.responseFromShare.listen((data) {
  18. // debugPrint(data);
  19. // });
  20. initPlatformState();
  21. }
  22. // Platform messages are asynchronous, so we initialize in an async method.
  23. Future<void> initPlatformState() async {
  24. String platformVersion;
  25. // Platform messages may fail, so we use a try/catch PlatformException.
  26. try {
  27. platformVersion = await FlutterAlibc.platformVersion;
  28. } on PlatformException {
  29. platformVersion = 'Failed to get platform version.';
  30. }
  31. // If the widget was removed from the tree while the asynchronous platform
  32. // message was in flight, we want to discard the reply rather than calling
  33. // setState to update our non-existent appearance.
  34. if (!mounted) return;
  35. setState(() {
  36. _platformVersion = platformVersion;
  37. });
  38. /* try {
  39. var initRes = await FlutterAlibc.initAlibc();
  40. } on Exception {}*/
  41. try {
  42. // var waite3s = await FlutterAlibc.openItemDetail(itemID: "12345");
  43. var result = await FlutterAlibc.initAlibc();
  44. print(result);
  45. } on Exception {}
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return MaterialApp(
  50. home: Scaffold(
  51. appBar: AppBar(
  52. title: const Text('Plugin example app'),
  53. ),
  54. body: Center(
  55. child: Column(
  56. children: <Widget>[
  57. FlatButton(
  58. child: Text("初始化阿里百川"),
  59. onPressed: () async {
  60. try {
  61. // var waite3s = await FlutterAlibc.openItemDetail(itemID: "12345");
  62. // 如果什么都不给
  63. var result = await FlutterAlibc.initAlibc();
  64. print("--------------");
  65. print(result.errorMessage+"\n"+result.errorCode);
  66. print("--------------");
  67. } on Exception {}
  68. },
  69. ),
  70. FlatButton(
  71. child: Text("登录淘宝"),
  72. onPressed: () async {
  73. var result = await FlutterAlibc.loginTaoBao();
  74. print("登录淘宝 ${result.data.nick} ${result.data.topAccessToken}");
  75. },
  76. ),
  77. FlatButton(
  78. child: Text("登出淘宝"),
  79. onPressed: () {
  80. FlutterAlibc.loginOut();
  81. },
  82. ),
  83. FlatButton(
  84. child: Text("淘客登录,渠道授权"),
  85. onPressed: () async {
  86. var result = await FlutterAlibc.taoKeLogin(
  87. url:
  88. "https://oauth.taobao.com/authorize?response_type=token&client_id=27646673&state=1212&view=wap",
  89. openType: AlibcOpenType.AlibcOpenTypeNative,
  90. isNeedCustomNativeFailMode: true,
  91. nativeFailMode: AlibcNativeFailMode.AlibcNativeFailModeJumpH5);
  92. print("access token ${result["accessToken"]}");
  93. },
  94. ),
  95. FlatButton(
  96. child: Text("淘客登录,新版渠道授权"),
  97. onPressed: () async {
  98. var result = await FlutterAlibc.taoKeLoginNew(
  99. "测试名字",
  100. "31333495"
  101. );
  102. print(result);
  103. print("access token ${result["accessToken"]}");
  104. },
  105. ),
  106. FlatButton(
  107. child: Text("唤起淘宝,openByUrl方式"),
  108. onPressed: () async {
  109. var result = await FlutterAlibc.openByUrl(
  110. url:
  111. "https://uland.taobao.com/coupon/edetail?e=0I2EBL%2BTWswGQASttHIRqRXxIesJCFV0jSsDEwaP11URqogtr65NL3IIxArmwXZQtYdj3OrQBBwJkllDQLUC%2B79fwBwwUiqlvyfAqbG%2BQWkG6QT52O7rmXYefz8NXcoYTJnbK5InWzlFfSAQOJJoy8NEaV3mm%2FQSzjZt5gElMznom9kMiklcP0KJ92VgfYGd&traceId=0b0d82cf15669814548736276e3d95&union_lens=lensId:0b0b6466_0c0d_16cd75f7c39_528f&xId=6MboRwsAi2s8Glbqt3lJLAwSlyrPyBLCZ01KOk6QzKCNhw8C6RjXgA1bNbZdKzp30gOqd1J5j1k7ei7HYId1QZ&ut_sk=1.utdid_null_1566981455011.TaoPassword-Outside.taoketop&sp_tk=77+lTU5nMllrdHRqSVLvv6U=",
  112. //backUrl: "tbopen27822502:https://h5.m.taobao.com",
  113. isNeedCustomNativeFailMode: true,
  114. nativeFailMode: AlibcNativeFailMode.AlibcNativeFailModeJumpH5);
  115. print(result);
  116. },
  117. ),
  118. FlatButton(
  119. child: Text("唤起淘宝,openItemDetail方式"),
  120. onPressed: () async {
  121. var result = await FlutterAlibc.openItemDetail(
  122. itemID: "575688730394",
  123. schemeType: AlibcSchemeType.AlibcSchemeTaoBao,
  124. isNeedCustomNativeFailMode: true,
  125. nativeFailMode: AlibcNativeFailMode.AlibcNativeFailModeJumpH5);
  126. print(result);
  127. },
  128. ),
  129. FlatButton(
  130. child: Text("打开店铺,openShop方式"),
  131. onPressed: () async {
  132. var result = await FlutterAlibc.openShop(shopId: "71955116");
  133. print(result);
  134. },
  135. ),
  136. FlatButton(
  137. child: Text("打开购物车,openCart方式"),
  138. onPressed: () async {
  139. var result = await FlutterAlibc.openCart();
  140. print(result);
  141. },
  142. ),
  143. FlatButton(
  144. child: Text("允许打点"),
  145. onPressed: () {
  146. FlutterAlibc.syncForTaoke(true);
  147. },
  148. ),
  149. FlatButton(
  150. child: Text("使用native Alipay"),
  151. onPressed: () {
  152. FlutterAlibc.useAlipayNative(true);
  153. },
  154. ),
  155. ],
  156. )),
  157. ),
  158. );
  159. }
  160. }