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
[![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)
[![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)

View File

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