From c44e9e512c8e376de1eb22a9a87639e0adfecdb7 Mon Sep 17 00:00:00 2001 From: JarvanMo Date: Mon, 27 Aug 2018 20:02:21 +0800 Subject: [PATCH] demo:share miniprogram --- example/lib/main.dart | 72 ++++++++++------- example/lib/share_mini_program.dart | 115 ++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 27 deletions(-) create mode 100644 example/lib/share_mini_program.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 26d4a20..d2eade4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:fluwx/fluwx.dart'; import 'package:fluwx_example/send_auth.dart'; +import 'package:fluwx_example/share_mini_program.dart'; import 'package:fluwx_example/share_video_page.dart'; import 'share_music.dart'; import 'share_web_page.dart'; @@ -31,11 +32,12 @@ class _MyAppState extends State { return new MaterialApp( routes: { "shareText": (context) => ShareTextPage(), - "shareImage":(context) => ShareImagePage(), - "shareWebPage":(context) => ShareWebPagePage(), - "shareMusic":(context) => ShareMusicPage(), - "shareVideo":(context) => ShareVideoPage(), - "sendAuth":(context) => SendAuthPage(), + "shareImage": (context) => ShareImagePage(), + "shareWebPage": (context) => ShareWebPagePage(), + "shareMusic": (context) => ShareMusicPage(), + "shareVideo": (context) => ShareVideoPage(), + "sendAuth": (context) => SendAuthPage(), + "shareMiniProgram":(context) => ShareMiniProgramPage() }, home: new Scaffold( appBar: new AppBar( @@ -54,43 +56,59 @@ class ShareSelectorPage extends StatelessWidget { children: [ Padding( padding: const EdgeInsets.all(8.0), - child: new OutlineButton(onPressed: () { - Navigator.of(context).pushNamed("shareText"); - }, child: const Text("share text")), + child: new OutlineButton( + onPressed: () { + Navigator.of(context).pushNamed("shareText"); + }, + child: const Text("share text")), ), Padding( padding: const EdgeInsets.all(8.0), - child: new OutlineButton(onPressed: () { - Navigator.of(context).pushNamed("shareImage"); - }, child: const Text("share image")), + child: new OutlineButton( + onPressed: () { + Navigator.of(context).pushNamed("shareImage"); + }, + child: const Text("share image")), ), Padding( padding: const EdgeInsets.all(8.0), - child: new OutlineButton(onPressed: () { - Navigator.of(context).pushNamed("shareWebPage"); - - }, child: const Text("share webpage")), + child: new OutlineButton( + onPressed: () { + Navigator.of(context).pushNamed("shareWebPage"); + }, + child: const Text("share webpage")), ), Padding( padding: const EdgeInsets.all(8.0), - child: new OutlineButton(onPressed: () { - Navigator.of(context).pushNamed("shareMusic"); - - }, child: const Text("share music")), + child: new OutlineButton( + onPressed: () { + Navigator.of(context).pushNamed("shareMusic"); + }, + child: const Text("share music")), ), Padding( padding: const EdgeInsets.all(8.0), - child: new OutlineButton(onPressed: () { - Navigator.of(context).pushNamed("shareVideo"); - - }, child: const Text("share video")), + child: new OutlineButton( + onPressed: () { + Navigator.of(context).pushNamed("shareVideo"); + }, + child: const Text("share video")), ), Padding( padding: const EdgeInsets.all(8.0), - child: new OutlineButton(onPressed: () { - Navigator.of(context).pushNamed("sendAuth"); - - }, child: const Text("send auth")), + child: new OutlineButton( + onPressed: () { + Navigator.of(context).pushNamed("shareMiniProgram"); + }, + child: const Text("share mini program")), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: new OutlineButton( + onPressed: () { + Navigator.of(context).pushNamed("sendAuth"); + }, + child: const Text("send auth")), ), ], ), diff --git a/example/lib/share_mini_program.dart b/example/lib/share_mini_program.dart new file mode 100644 index 0000000..35e43d4 --- /dev/null +++ b/example/lib/share_mini_program.dart @@ -0,0 +1,115 @@ +import 'package:flutter/material.dart'; +import 'package:fluwx/fluwx.dart'; + +class ShareMiniProgramPage extends StatefulWidget { + @override + _ShareMiniProgramPageState createState() => _ShareMiniProgramPageState(); +} + +class _ShareMiniProgramPageState extends State { + + Fluwx fluwx; + WeChatScene scene = WeChatScene.SESSION; + String _webPageUr = "http://www.qq.com"; + String _thumbnail = + "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534614311230&di=b17a892b366b5d002f52abcce7c4eea0&imgtype=0&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png"; + String _title = "Fluwx"; + String _userName = "gh_d43f693ca31f"; + String _path = "/pages/media"; + String _description = "Fluwx"; + + @override + void initState() { + super.initState(); + fluwx = new Fluwx(); + } + + + @override + Widget build(BuildContext context) { + new Scaffold( + appBar: AppBar( + title: const Text("ShareMiniProgram"), + actions: [ + IconButton(icon: Icon(Icons.share,color: Colors.white,), onPressed: _share) + ], + ), + + body: Padding( + padding: const EdgeInsets.all(8.0), + child: new Column( + children: [ + new TextField( + controller: TextEditingController(text: "http://www.qq.com"), + onChanged: (str){ + _webPageUr = str; + }, + decoration: InputDecoration( + labelText: "web page url" + ), + ), + new TextField( + controller: TextEditingController(text: "gh_d43f693ca31f"), + onChanged: (str){ + _userName = str; + }, + decoration: InputDecoration( + labelText: "user name" + ), + ), + new TextField( + controller: TextEditingController(text: "/pages/media"), + onChanged: (str){ + _path = str; + }, + decoration: InputDecoration( + labelText: "user name" + ), + ), + new TextField( + controller: TextEditingController(text: "Fluwx"), + onChanged: (str){ + _title = str; + }, + decoration: InputDecoration( + labelText: "title" + ), + ), + new TextField( + controller: TextEditingController(text: "Fluwx"), + onChanged: (str){ + _description = str; + }, + decoration: InputDecoration( + labelText: "description" + ), + ), + new TextField( + controller: TextEditingController(text: "assets://images/logo.png"), + onChanged: (str){ + _thumbnail = str; + }, + decoration: InputDecoration( + labelText: "thumbnail" + ), + ), + ], + ), + ), + ); + } + + void _share() { + var model =new WeChatShareMiniProgramModel( + webPageUrl: _webPageUr, + miniProgramType: WeChatShareMiniProgramModel.MINI_PROGRAM_TYPE_RELEASE, + userName: _userName, + title: _title, + description: _description, + thumbnail: _thumbnail + ); + fluwx.share(model); + } + + +}