Skip to content

Commit f559c74

Browse files
authored
Merge pull request alibaba#206 from Nealyang/master
登陆
2 parents 7fdca1e + 58ef9c6 commit f559c74

24 files changed

+643
-83
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Language: [English](https://github.com/alibaba/flutter-go/blob/master/README-en.
2525

2626
android下载地址:
2727

28-
<img src="https://img.alicdn.com/tfs/TB1jGgfQ7voK1RjSZFNXXcxMVXa-438-426.png" width="200px">
28+
<img src="https://img.alicdn.com/tfs/TB1ylxGTMHqK1RjSZFgXXa7JXXa-436-432.png" width="200px">
2929

3030
iphone下载地址:
3131
暂无

android/.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>android</name>
4+
<comment>Project android created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
connection.project.dir=
2+
eclipse.preferences.version=1

android/app/.classpath

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
4+
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5+
<classpathentry kind="output" path="bin/default"/>
6+
</classpath>

android/app/.project

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>app</name>
4+
<comment>Project app created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22+
</natures>
23+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
connection.project.dir=..
2+
eclipse.preferences.version=1

assets/app.db

4 KB
Binary file not shown.

assets/images/FlutterGo.png

1.04 KB
Loading

ios/Runner.xcodeproj/project.pbxproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@
511511
buildSettings = {
512512
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
513513
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = Launch2;
514+
CODE_SIGN_IDENTITY = "iPhone Distribution";
514515
CODE_SIGN_STYLE = Manual;
515516
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
516517
DEVELOPMENT_TEAM = 4WLT68XRNA;
@@ -527,7 +528,7 @@
527528
);
528529
PRODUCT_BUNDLE_IDENTIFIER = com.alibaba.fluttergo;
529530
PRODUCT_NAME = "$(TARGET_NAME)";
530-
PROVISIONING_PROFILE_SPECIFIER = "FlutterGO-alibaba-develop";
531+
PROVISIONING_PROFILE_SPECIFIER = FlutterGO_alibaba_distribution_app_store;
531532
VERSIONING_SYSTEM = "apple-generic";
532533
};
533534
name = Debug;

lib/api/api.dart

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Api{
2+
// static const String BASE_URL = 'http://127.0.0.1:6001/';
3+
static const String BASE_URL = 'http://flutter-go.alibaba.net/';
4+
5+
static const String DO_LOGIN = BASE_URL+'doLogin';//登陆
6+
7+
static const String CHECK_LOGIN = BASE_URL+'checkLogin';//验证登陆
8+
9+
static const String LOGOUT = BASE_URL+'logout';//退出登陆
10+
}

lib/components/widget_demo.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class _WidgetDemoState extends State<WidgetDemo> {
101101
// 插入操作
102102
_collectionControl
103103
.insert(Collection(name: widget.title, router: _router))
104-
.then((result) {
104+
.then((result) {
105105
if (this.mounted) {
106106
setState(() {
107107
_hasCollected = true;

lib/main.dart

+49-15
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,73 @@ import 'package:fluro/fluro.dart';
33
import 'package:flutter/rendering.dart';
44
import 'routers/routers.dart';
55
import 'routers/application.dart';
6-
6+
import 'package:flutter_spinkit/flutter_spinkit.dart';
77
import 'package:flutter_go/utils/provider.dart';
88
import 'package:flutter_go/utils/shared_preferences.dart';
99
import 'package:flutter_go/views/home.dart';
1010
import 'package:flutter_go/model/search_history.dart';
1111
import 'package:flutter_go/utils/analytics.dart' as Analytics;
12+
import 'package:flutter_go/views/login_page/login_page.dart';
13+
import 'package:flutter_go/utils/data_utils.dart';
14+
1215
//import 'views/welcome_page/index.dart';
1316

1417
const int ThemeColor = 0xFFC91B3A;
1518
SpUtil sp;
1619
var db;
1720

18-
class MyApp extends StatelessWidget {
19-
MyApp() {
21+
class MyApp extends StatefulWidget {
22+
MyApp() {
2023
final router = new Router();
2124

2225
Routes.configureRoutes(router);
2326

2427
Application.router = router;
2528
}
29+
30+
@override
31+
_MyAppState createState() => _MyAppState();
32+
}
33+
34+
class _MyAppState extends State<MyApp> {
35+
bool _hasLogin = false;
36+
bool _isLoading = true;
37+
38+
@override
39+
void initState() {
40+
super.initState();
41+
DataUtils.checkLogin().then((hasLogin) {
42+
setState(() {
43+
_hasLogin = hasLogin;
44+
_isLoading = false;
45+
});
46+
}).catchError((onError){
47+
setState(() {
48+
_hasLogin = true;
49+
_isLoading = false;
50+
});
51+
print('身份信息验证失败:$onError');
52+
});
53+
}
54+
2655
showWelcomePage() {
27-
// 暂时关掉欢迎介绍
28-
return AppPage();
29-
// bool showWelcome = sp.getBool(SharedPreferencesKeys.showWelcome);
30-
// if (showWelcome == null || showWelcome == true) {
31-
// return WelcomePage();
32-
// } else {
33-
// return AppPage();
34-
// }
56+
if (_isLoading) {
57+
return Container(
58+
color: const Color(ThemeColor),
59+
child: Center(
60+
child: SpinKitPouringHourglass(color: Colors.white),
61+
),
62+
);
63+
} else {
64+
// 判断是否已经登录
65+
if (_hasLogin) {
66+
return AppPage();
67+
} else {
68+
return LoginPage();
69+
}
70+
}
3571
}
72+
3673
@override
3774
Widget build(BuildContext context) {
3875
return new MaterialApp(
@@ -50,17 +87,14 @@ class MyApp extends StatelessWidget {
5087
size: 35.0,
5188
),
5289
),
53-
home: new Scaffold(
54-
body: showWelcomePage()
55-
),
90+
home: new Scaffold(body: showWelcomePage()),
5691
debugShowCheckedModeBanner: false,
5792
onGenerateRoute: Application.router.generator,
5893
navigatorObservers: <NavigatorObserver>[Analytics.observer],
5994
);
6095
}
6196
}
6297

63-
6498
void main() async {
6599
final provider = new Provider();
66100
await provider.init(true);

lib/model/user_info.dart

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class UserInfo {
2+
String username;
3+
int id;
4+
String avatarPic;
5+
String themeColor;
6+
String urlName;
7+
8+
UserInfo({
9+
this.avatarPic,
10+
this.id,
11+
this.themeColor,
12+
this.urlName,
13+
this.username,
14+
});
15+
16+
factory UserInfo.fromJson(Map<String, dynamic> json) {
17+
return UserInfo(
18+
avatarPic: json['avatar_pic'],
19+
id: int.parse(json['id']),
20+
username: json['name'],
21+
themeColor: json['theme_color'],
22+
urlName: json['url_name']);
23+
}
24+
}

lib/model/user_info_cache.dart

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/// @Author: 一凨
2+
/// @Date: 2019-01-07 16:24:42
3+
/// @Last Modified by: 一凨
4+
/// @Last Modified time: 2019-01-08 17:37:42
5+
6+
import 'dart:async';
7+
8+
import 'package:flutter_go/utils/sql.dart';
9+
10+
abstract class UserInfoInterface {
11+
String get username;
12+
String get password;
13+
}
14+
15+
class UserInfo implements UserInfoInterface {
16+
String username;
17+
String password;
18+
19+
UserInfo({this.username, this.password});
20+
21+
factory UserInfo.fromJSON(Map json){
22+
return UserInfo(username: json['username'],password: json['password']);
23+
}
24+
25+
Object toMap() {
26+
return {'username': username, 'password': password};
27+
}
28+
}
29+
30+
class UserInfoControlModel {
31+
final String table = 'userInfo';
32+
Sql sql;
33+
34+
UserInfoControlModel() {
35+
sql = Sql.setTable(table);
36+
}
37+
38+
// 获取所有的收藏
39+
40+
// 插入新的缓存
41+
Future insert(UserInfo userInfo) {
42+
var result =
43+
sql.insert({'username': userInfo.username, 'password': userInfo.password});
44+
return result;
45+
}
46+
47+
// 获取用户信息
48+
Future<List<UserInfo>> getAllInfo() async {
49+
List list = await sql.getByCondition();
50+
List<UserInfo> resultList = [];
51+
list.forEach((item){
52+
print(item);
53+
resultList.add(UserInfo.fromJSON(item));
54+
});
55+
return resultList;
56+
}
57+
58+
// 清空表中数据
59+
Future deleteAll() async{
60+
return await sql.deleteAll();
61+
}
62+
}

lib/routers/router_handler.dart

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import '../widgets/404.dart';
66
import 'package:flutter_go/components/full_screen_code_dialog.dart';
77
import 'package:flutter_go/views/web_page/web_view_page.dart';
88
import 'package:flutter_go/views/home.dart';
9+
import 'package:flutter_go/views/login_page/login_page.dart';
910

1011
// app的首页
1112
var homeHandler = new Handler(
@@ -26,6 +27,10 @@ var widgetNotFoundHandler = new Handler(
2627
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
2728
return new WidgetNotFound();
2829
});
30+
var loginPageHandler = new Handler(
31+
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
32+
return LoginPage();
33+
});
2934

3035
var fullScreenCodeDialog = new Handler(
3136
handlerFunc: (BuildContext context, Map<String, List<String>> params) {

lib/routers/routers.dart

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Routes {
1212
static String widgetDemo = '/widget-demo';
1313
static String codeView = '/code-view';
1414
static String webViewPage = '/web-view-page';
15+
static String loginPage = '/loginpage';
1516

1617
static void configureRoutes(Router router) {
1718
List widgetDemosList = new WidgetDemoList().getDemos();
@@ -22,6 +23,7 @@ class Routes {
2223

2324
router.define('/category/:type', handler: categoryHandler);
2425
router.define('/category/error/404', handler: widgetNotFoundHandler);
26+
router.define(loginPage, handler: loginPageHandler);
2527
router.define(codeView,handler:fullScreenCodeDialog);
2628
router.define(webViewPage,handler:webViewPageHand);
2729
widgetDemosList.forEach((demo) {

lib/utils/data_utils.dart

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'dart:async' show Future;
2+
3+
import './net_utils.dart';
4+
import '../model/user_info.dart';
5+
import 'package:flutter_go/api/api.dart';
6+
7+
8+
class DataUtils{
9+
// 登陆获取用户信息
10+
static Future<UserInfo> doLogin(Map<String,String> params) async{
11+
var response = await NetUtils.post(Api.DO_LOGIN, params);
12+
UserInfo userInfo = UserInfo.fromJson(response['data']);
13+
return userInfo;
14+
}
15+
16+
// 验证登陆
17+
18+
static Future<bool> checkLogin() async{
19+
var response = await NetUtils.get(Api.CHECK_LOGIN);
20+
print('验证登陆:$response');
21+
return response['success'];
22+
}
23+
24+
// 退出登陆
25+
static Future<bool> logout() async{
26+
var response = await NetUtils.get(Api.LOGOUT);
27+
print('退出登陆 $response');
28+
return response['success'];
29+
}
30+
}

0 commit comments

Comments
 (0)