智莺生活APP的阿里百川 Flutter 插件
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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