Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yubo5 committed May 16, 2019
1 parent b823f96 commit 7f8caf4
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 191 deletions.
14 changes: 7 additions & 7 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

302 changes: 174 additions & 128 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified apk/app-release.apk
Binary file not shown.
12 changes: 6 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/shared_preferences/ios"

SPEC CHECKSUMS:
barcode_scan: 8288e70cb430072003bce2c794a1431e7adbcb4d
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
flutter_webview_plugin: 0b491d31c34ab5c86a71c9f1a57ac000dd1b75e9
image_picker: ee00aab0487cedc80a304085219503cc6d0f2e22
barcode_scan: 33f586d02270046fc6559135038b34b5754eaa4f
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
flutter_webview_plugin: ed9e8a6a96baf0c867e90e1bce2673913eeac694
image_picker: a211f28b95a560433c00f5cd3773f4710a20404d
MTBBarcodeScanner: bb0bb62e18b57f8a571a482248adc20722b70a91
shared_preferences: 5a1d487c427ee18fcd3ea1f2a131569481834b53
shared_preferences: 1feebfa37bb57264736e16865e7ffae7fc99b523

PODFILE CHECKSUM: 1e5af4103afd21ca5ead147d7b81d06f494f51a2

COCOAPODS: 1.5.3
COCOAPODS: 1.7.0.beta.3
27 changes: 17 additions & 10 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -41,7 +40,8 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
182DB731E25E2A38A44FAFF7 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
1C61375D564E6F057C0AB0C1 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -84,7 +84,6 @@
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
Expand Down Expand Up @@ -141,6 +140,8 @@
AF1367F5F6AF0881D93C1A67 /* Pods */ = {
isa = PBXGroup;
children = (
182DB731E25E2A38A44FAFF7 /* Pods-Runner.debug.xcconfig */,
1C61375D564E6F057C0AB0C1 /* Pods-Runner.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
Expand Down Expand Up @@ -181,6 +182,8 @@
TargetAttributes = {
97C146ED1CF9000F007C117D = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 4ZACZ79DU9;
ProvisioningStyle = Automatic;
};
};
};
Expand All @@ -189,6 +192,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand All @@ -211,7 +215,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -260,21 +263,17 @@
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
Expand Down Expand Up @@ -433,7 +432,10 @@
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 4ZACZ79DU9;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -447,6 +449,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.yubo.flutterOsc;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
Expand All @@ -456,7 +459,10 @@
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 4ZACZ79DU9;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -470,6 +476,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.yubo.flutterOsc;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
Expand Down
10 changes: 5 additions & 5 deletions lib/api/Api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Api {
static final String host = "https://www.oschina.net";

// 资讯列表
static final String newsList = "http://osc.yubo725.top/news/list";
static final String newsList = "http://osc.yubo.me/news/list";

// 资讯详情
static final String newsDetail = host + "/action/openapi/news_detail";
Expand All @@ -23,14 +23,14 @@ class Api {
static final String pubTweet = host + "/action/openapi/tweet_pub";

// 添加到小黑屋
static final String addToBlack = "http://osc.yubo725.top/black/add";
static final String addToBlack = "http://osc.yubo.me/black/add";

// 查询小黑屋
static final String queryBlack = "http://osc.yubo725.top/black/query";
static final String queryBlack = "http://osc.yubo.me/black/query";

// 从小黑屋中删除
static final String deleteBlack = "http://osc.yubo725.top/black/delete";
static final String deleteBlack = "http://osc.yubo.me/black/delete";

// 开源活动
static final String eventList = "http://osc.yubo725.top/events/";
static final String eventList = "http://osc.yubo.me/events/";
}
2 changes: 1 addition & 1 deletion lib/constants/Constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:event_bus/event_bus.dart';

class Constants {

static final String redirectUrl = "http://yubo725.top/osc/osc.php";
static final String redirectUrl = "http://osc.yubo.me/logincallback";

static final String loginUrl = "https://www.oschina.net/action/oauth2/authorize?client_id=4rWcDXCNTV5gMWxtagxI&response_type=code&redirect_uri=" + redirectUrl;

Expand Down
20 changes: 14 additions & 6 deletions lib/pages/LoginPage.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'dart:async';
import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

import '../constants/Constants.dart';
import 'package:flutter/cupertino.dart';
import 'dart:convert';
import '../util/DataUtils.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

// 登录页面,使用网页加载的开源中国三方登录页面
class LoginPage extends StatefulWidget {
Expand All @@ -17,6 +19,8 @@ class LoginPageState extends State<LoginPage> {
bool loading = true;
// 标记当前页面是否是我们自定义的回调页面
bool isLoadingCallbackPage = false;
// 是否解析了结果,这个字段用于确保parseResult方法只调用一次,真是MMP噢,不用这个字段标记,parseResult就调用了两次,导致黑屏产生,查黑屏问题用了我一天时间!
bool parsedResult = false;
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
// URL变化监听器
StreamSubscription<String> _onUrlChanged;
Expand Down Expand Up @@ -58,15 +62,19 @@ class LoginPageState extends State<LoginPage> {
_onUrlChanged = flutterWebViewPlugin.onUrlChanged.listen((url) {
// 登录成功会跳转到自定义的回调页面,该页面地址为http://yubo725.top/osc/osc.php?code=xxx
// 该页面会接收code,然后根据code换取AccessToken,并将获取到的token及其他信息,通过js的get()方法返回
if (url != null && url.length > 0 && url.contains("osc/osc.php?code=")) {
if (url != null && url.length > 0 && url.contains("/logincallback?")) {
isLoadingCallbackPage = true;
}
});
}

// 解析WebView中的数据
void parseResult() {
flutterWebViewPlugin.evalJavascript("get();").then((result) {
if (parsedResult) {
return;
}
parsedResult = true;
flutterWebViewPlugin.evalJavascript("window.atob(get())").then((result) {
// result json字符串,包含token信息
if (result != null && result.length > 0) {
// 拿到了js中的数据
Expand All @@ -82,7 +90,7 @@ class LoginPageState extends State<LoginPage> {
Navigator.pop(context, "refresh");
}
} catch (e) {
print("parse login result error: $e");
print(e);
}
}
});
Expand Down
32 changes: 18 additions & 14 deletions lib/pages/MyInfoPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,24 @@ class MyInfoPageState extends State<MyInfoPage> {

// 获取用户信息
getUserInfo() async {
SharedPreferences sp = await SharedPreferences.getInstance();
String accessToken = sp.get(DataUtils.SP_AC_TOKEN);
Map<String, String> params = Map();
params['access_token'] = accessToken;
NetUtils.get(Api.userInfo, params: params).then((data) {
if (data != null) {
var map = json.decode(data);
setState(() {
userAvatar = map['avatar'];
userName = map['name'];
});
DataUtils.saveUserInfo(map);
}
});
try {
SharedPreferences sp = await SharedPreferences.getInstance();
String accessToken = sp.get(DataUtils.SP_AC_TOKEN);
Map<String, String> params = Map();
params['access_token'] = accessToken;
NetUtils.get(Api.userInfo, params: params).then((data) {
if (data != null) {
var map = json.decode(data);
setState(() {
userAvatar = map['avatar'];
userName = map['name'];
});
DataUtils.saveUserInfo(map);
}
});
} catch (e) {
print(e);
}
}

_login() async {
Expand Down
13 changes: 9 additions & 4 deletions lib/pages/NewLoginPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class NewLoginPageState extends State<NewLoginPage> {
bool isOnLogin = false;
// 是否隐藏输入的文本
bool obscureText = true;
// 是否解析了结果
bool parsedResult = false;

final usernameCtrl = TextEditingController(text: '');
final passwordCtrl = TextEditingController(text: '');
Expand Down Expand Up @@ -104,9 +106,8 @@ class NewLoginPageState extends State<NewLoginPage> {
_onUrlChanged = flutterWebViewPlugin.onUrlChanged.listen((url) {
// 登录成功会跳转到自定义的回调页面,该页面地址为http://yubo725.top/osc/osc.php?code=xxx
// 该页面会接收code,然后根据code换取AccessToken,并将获取到的token及其他信息,通过js的get()方法返回
if (url != null && url.length > 0 && url.contains("osc/osc.php?code=")) {
if (url != null && url.length > 0 && url.contains("/logincallback?")) {
isLoadingCallbackPage = true;
print("URL变为回调页");
}
});
}
Expand Down Expand Up @@ -140,7 +141,11 @@ class NewLoginPageState extends State<NewLoginPage> {

// 解析WebView中的数据
void parseResult() {
flutterWebViewPlugin.evalJavascript("get();").then((result) {
if (parsedResult) {
return;
}
parsedResult = true;
flutterWebViewPlugin.evalJavascript("window.atob(get())").then((result) {
// result json字符串,包含token信息
if (result != null && result.length > 0) {
// 拿到了js中的数据
Expand Down Expand Up @@ -215,8 +220,8 @@ class NewLoginPageState extends State<NewLoginPage> {
height: 0.0,
child: WebviewScaffold(
key: _scaffoldKey,
url: Constants.loginUrl, // 登录的URL
hidden: true,
url: Constants.loginUrl, // 登录的URL
withZoom: true, // 允许网页缩放
withLocalStorage: true, // 允许LocalStorage
withJavascript: true, // 允许执行js代码
Expand Down
Loading

0 comments on commit 7f8caf4

Please sign in to comment.