This commit is contained in:
v7lin 2019-05-17 11:49:54 +08:00
parent 46ca74c62b
commit d44b5a8080
3 changed files with 37 additions and 39 deletions

View File

@ -1,6 +1,7 @@
# fake_weibo # fake_weibo
[![Build Status](https://cloud.drone.io/api/badges/v7lin/fake_weibo/status.svg)](https://cloud.drone.io/v7lin/fake_weibo) [![Build Status](https://cloud.drone.io/api/badges/v7lin/fake_weibo/status.svg)](https://cloud.drone.io/v7lin/fake_weibo)
[![Codecov](https://codecov.io/gh/v7lin/fake_weibo/branch/master/graph/badge.svg)](https://codecov.io/gh/v7lin/fake_weibo)
[![GitHub Tag](https://img.shields.io/github/tag/v7lin/fake_weibo.svg)](https://github.com/v7lin/fake_weibo/releases) [![GitHub Tag](https://img.shields.io/github/tag/v7lin/fake_weibo.svg)](https://github.com/v7lin/fake_weibo/releases)
[![Pub Package](https://img.shields.io/pub/v/fake_weibo.svg)](https://pub.dartlang.org/packages/fake_weibo) [![Pub Package](https://img.shields.io/pub/v/fake_weibo.svg)](https://pub.dartlang.org/packages/fake_weibo)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/v7lin/fake_weibo/blob/master/LICENSE) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/v7lin/fake_weibo/blob/master/LICENSE)

View File

@ -46,6 +46,11 @@ android {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug signingConfig signingConfigs.debug
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
} }

View File

@ -5,11 +5,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:fake_weibo/fake_weibo.dart'; import 'package:fake_weibo/fake_weibo.dart';
const String _WEIBO_APP_KEY = '3393861383';
const List<String> _WEIBO_SCOPE = <String>[
WeiboScope.ALL,
];
void main() { void main() {
runZoned(() { runZoned(() {
runApp(MyApp()); runApp(MyApp());
@ -28,27 +23,13 @@ void main() {
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Weibo weibo = Weibo() return MaterialApp(
..registerApp( home: Home(),
appKey: _WEIBO_APP_KEY,
scope: _WEIBO_SCOPE,
);
return WeiboProvider(
weibo: weibo,
child: MaterialApp(
home: Home(
weibo: weibo,
),
),
); );
} }
} }
class Home extends StatefulWidget { class Home extends StatefulWidget {
Home({Key key, @required this.weibo}) : super(key: key);
final Weibo weibo;
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
return _HomeState(); return _HomeState();
@ -56,6 +37,13 @@ class Home extends StatefulWidget {
} }
class _HomeState extends State<Home> { class _HomeState extends State<Home> {
static const String _WEIBO_APP_KEY = '3393861383';
static const List<String> _WEIBO_SCOPE = <String>[
WeiboScope.ALL,
];
Weibo _weibo = Weibo();
StreamSubscription<WeiboAuthResp> _auth; StreamSubscription<WeiboAuthResp> _auth;
StreamSubscription<WeiboSdkResp> _share; StreamSubscription<WeiboSdkResp> _share;
@ -64,8 +52,12 @@ class _HomeState extends State<Home> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_auth = widget.weibo.authResp().listen(_listenAuth); _weibo.registerApp(
_share = widget.weibo.shareMsgResp().listen(_listenShareMsg); appKey: _WEIBO_APP_KEY,
scope: _WEIBO_SCOPE,
);
_auth = _weibo.authResp().listen(_listenAuth);
_share = _weibo.shareMsgResp().listen(_listenShareMsg);
} }
void _listenAuth(WeiboAuthResp resp) { void _listenAuth(WeiboAuthResp resp) {
@ -94,33 +86,32 @@ class _HomeState extends State<Home> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Fake Weibo Demo'), title: const Text('Fake Weibo Demo'),
), ),
body: ListView( body: ListView(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
title: Text('环境检查'), title: const Text('环境检查'),
onTap: () async { onTap: () async {
String content = String content = 'weibo: ${await _weibo.isWeiboInstalled()}';
'weibo: ${await widget.weibo.isWeiboInstalled()}';
_showTips('环境检查', content); _showTips('环境检查', content);
}, },
), ),
ListTile( ListTile(
title: Text('登录'), title: const Text('登录'),
onTap: () { onTap: () {
widget.weibo.auth( _weibo.auth(
appKey: _WEIBO_APP_KEY, appKey: _WEIBO_APP_KEY,
scope: _WEIBO_SCOPE, scope: _WEIBO_SCOPE,
); );
}, },
), ),
ListTile( ListTile(
title: Text('用户信息'), title: const Text('用户信息'),
onTap: () async { onTap: () async {
if (_authResp != null && if (_authResp != null &&
_authResp.errorCode == WeiboSdkResp.SUCCESS) { _authResp.errorCode == WeiboSdkResp.SUCCESS) {
WeiboUserInfoResp userInfoResp = await widget.weibo.getUserInfo( WeiboUserInfoResp userInfoResp = await _weibo.getUserInfo(
appkey: _WEIBO_APP_KEY, appkey: _WEIBO_APP_KEY,
userId: _authResp.userId, userId: _authResp.userId,
accessToken: _authResp.accessToken, accessToken: _authResp.accessToken,
@ -137,33 +128,34 @@ class _HomeState extends State<Home> {
}, },
), ),
ListTile( ListTile(
title: Text('文字分享'), title: const Text('文字分享'),
onTap: () { onTap: () {
widget.weibo.shareText( _weibo.shareText(
text: 'Share Text', text: 'Share Text',
); );
}, },
), ),
ListTile( ListTile(
title: Text('图片分享'), title: const Text('图片分享'),
onTap: () async { onTap: () async {
AssetImage image = AssetImage('images/icon/timg.jpeg'); AssetImage image = const AssetImage('images/icon/timg.jpeg');
AssetBundleImageKey key = AssetBundleImageKey key =
await image.obtainKey(createLocalImageConfiguration(context)); await image.obtainKey(createLocalImageConfiguration(context));
ByteData imageData = await key.bundle.load(key.name); ByteData imageData = await key.bundle.load(key.name);
await widget.weibo.shareImage( await _weibo.shareImage(
imageData: imageData.buffer.asUint8List(), imageData: imageData.buffer.asUint8List(),
); );
}, },
), ),
ListTile( ListTile(
title: Text('网页分享'), title: const Text('网页分享'),
onTap: () async { onTap: () async {
AssetImage image = AssetImage('images/icon/ic_launcher.png'); AssetImage image =
const AssetImage('images/icon/ic_launcher.png');
AssetBundleImageKey key = AssetBundleImageKey key =
await image.obtainKey(createLocalImageConfiguration(context)); await image.obtainKey(createLocalImageConfiguration(context));
ByteData thumbData = await key.bundle.load(key.name); ByteData thumbData = await key.bundle.load(key.name);
await widget.weibo.shareWebpage( await _weibo.shareWebpage(
title: 'title', title: 'title',
description: 'share webpage', description: 'share webpage',
thumbData: thumbData.buffer.asUint8List(), thumbData: thumbData.buffer.asUint8List(),