Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
netrain_flutter_app
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
邹志胜
netrain_flutter_app
Commits
54d95d5c
Commit
54d95d5c
authored
Jul 09, 2021
by
窦文
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.naiterui.com:zouzhisheng/netrain_flutter_app
parents
e7e593fa
55a78b39
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
347 additions
and
81 deletions
+347
-81
AppColors.dart
netrain_flutter_app/lib/common/AppColors.dart
+10
-0
Images.dart
netrain_flutter_app/lib/common/Images.dart
+0
-0
dwMain.dart
netrain_flutter_app/lib/douwen/dwMain.dart
+1
-1
layout_page.dart
netrain_flutter_app/lib/laishanqi/layout_page.dart
+4
-2
HomePage.dart
netrain_flutter_app/lib/laishanqi/netrain/HomePage.dart
+1
-1
RegisterPage.dart
..._flutter_app/lib/laishanqi/netrain/user/RegisterPage.dart
+61
-21
loginPage.dart
...ain_flutter_app/lib/laishanqi/netrain/user/loginPage.dart
+16
-4
main.dart
netrain_flutter_app/lib/main.dart
+36
-29
car_details.dart
netrain_flutter_app/lib/xuehao/car_details.dart
+49
-0
list_page.dart
netrain_flutter_app/lib/xuehao/list_page.dart
+46
-14
LoginApi.dart
netrain_flutter_app/lib/zhangfeng/LoginApi.dart
+8
-3
LoginPage.dart
netrain_flutter_app/lib/zhangfeng/LoginPage.dart
+22
-2
BaseHttpModel.dart
netrain_flutter_app/lib/zhangfeng/Network/BaseHttpModel.dart
+1
-1
HttpManager.dart
netrain_flutter_app/lib/zhangfeng/Network/HttpManager.dart
+4
-2
UserData.dart
netrain_flutter_app/lib/zhangfeng/UserData.dart
+50
-0
UserModel.dart
netrain_flutter_app/lib/zhangfeng/UserModel.dart
+16
-0
UserModel.g.dart
netrain_flutter_app/lib/zhangfeng/UserModel.g.dart
+21
-0
pubspec.yaml
netrain_flutter_app/pubspec.yaml
+1
-1
No files found.
netrain_flutter_app/lib/common/AppColors.dart
0 → 100644
View file @
54d95d5c
/// 项目颜色配置
class
AppColors
{
/// 主色
static
const
mainColor
=
0xff2893FF
;
/// hint颜色
static
const
hintText
=
0xffb4b4b4
;
/// 输入框字体颜色
static
const
EditTextColor
=
0xff333333
;
}
\ No newline at end of file
netrain_flutter_app/lib/
laishanqi/netrai
n/Images.dart
→
netrain_flutter_app/lib/
commo
n/Images.dart
View file @
54d95d5c
File moved
netrain_flutter_app/lib/douwen/dwMain.dart
View file @
54d95d5c
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:netrain_flutter_app/
laishanqi/netrai
n/Images.dart'
;
import
'package:netrain_flutter_app/
commo
n/Images.dart'
;
import
'secondpage.dart'
;
import
'secondpage.dart'
;
...
...
netrain_flutter_app/lib/laishanqi/layout_page.dart
View file @
54d95d5c
...
@@ -42,9 +42,11 @@ class _LayoutGroupState extends State<LayoutPage> {
...
@@ -42,9 +42,11 @@ class _LayoutGroupState extends State<LayoutPage> {
blurRadius:
15
,
blurRadius:
15
,
spreadRadius:
-
5
)
spreadRadius:
-
5
)
]),
]),
child:
Rais
edButton
(
child:
Elevat
edButton
(
child:
Text
(
"按钮"
),
child:
Text
(
"按钮"
),
onPressed:
()
{},
onPressed:
()
{
Navigator
.
pushNamed
(
context
,
"register"
);
},
)),
)),
Container
(
Container
(
margin:
EdgeInsets
.
all
(
10
),
margin:
EdgeInsets
.
all
(
10
),
...
...
netrain_flutter_app/lib/laishanqi/netrain/HomePage.dart
View file @
54d95d5c
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'Images.dart'
;
import
'
../../common/
Images.dart'
;
class
HomePage
extends
StatefulWidget
{
class
HomePage
extends
StatefulWidget
{
@override
@override
...
...
netrain_flutter_app/lib/laishanqi/netrain/user/RegisterPage.dart
View file @
54d95d5c
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:netrain_flutter_app/common/AppColors.dart'
;
import
'package:netrain_flutter_app/douwen/dwMain.dart'
;
/**
/**
* 注册页
* 注册页
*/
*/
class
RegisterPage
extends
StatefulWidget
{
class
RegisterPage
extends
StatefulWidget
{
@override
@override
State
createState
()
=>
_RegisterState
();
State
createState
()
=>
_RegisterState
();
}
}
class
_RegisterState
extends
State
{
class
_RegisterState
extends
State
{
// 输入框控制器
final
nameController
=
TextEditingController
();
final
phoneController
=
TextEditingController
();
final
codeController
=
TextEditingController
();
final
passwordController
=
TextEditingController
();
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
// 获取上一个页面的传值
List
<
String
>
args
=
ModalRoute
.
of
(
context
).
settings
.
arguments
;
phoneController
.
text
=
args
.
first
;
return
registerWidget
();
return
registerWidget
();
}
}
Widget
registerWidget
()
{
@override
void
dispose
()
{
super
.
dispose
();
nameController
.
dispose
();
phoneController
.
dispose
();
codeController
.
dispose
();
passwordController
.
dispose
();
}
Widget
registerWidget
()
{
return
MaterialApp
(
return
MaterialApp
(
theme:
ThemeData
(
theme:
ThemeData
(
primaryColor:
Colors
.
white
,
primaryColor:
Colors
.
white
,
...
@@ -27,22 +46,43 @@ class _RegisterState extends State{
...
@@ -27,22 +46,43 @@ class _RegisterState extends State{
appBar:
AppBar
(
appBar:
AppBar
(
leading:
IconButton
(
leading:
IconButton
(
icon:
Icon
(
Icons
.
arrow_back
),
icon:
Icon
(
Icons
.
arrow_back
),
onPressed:
(){
onPressed:
()
{
Navigator
.
of
(
context
).
pushNamed
(
"/"
);
Navigator
.
of
(
context
).
popUntil
(
ModalRoute
.
withName
(
"main"
));
// Navigator.of(context).pushNamed("login2");
},
},
),
),
centerTitle:
true
,
centerTitle:
true
,
title:
Text
(
"注册"
),
title:
Text
(
"注册"
),
elevation:
0
,
elevation:
0
,
),
),
body:
ListView
(
body:
Container
(
margin:
EdgeInsets
.
fromLTRB
(
16
,
16
,
16
,
0
),
child:
ListView
(
children:
[
children:
[
_getTextField
(
"请输入姓名"
,
nameController
),
_getTextField
(
"请输入手机号码"
,
phoneController
),
Stack
(
children:
[
_getTextField
(
"请输入验证码"
,
codeController
),
// Positioned(child: )
],),
_getTextField
(
"请输入9-16位密码"
,
passwordController
),
],
],
),
),
),
)
),
);
);
}
}
/// 输入框
Widget
_getTextField
(
String
hintText
,
TextEditingController
controller
){
return
TextField
(
style:
TextStyle
(
color:
Color
(
AppColors
.
EditTextColor
),
fontSize:
16
),
decoration:
InputDecoration
(
hintText:
hintText
,
hintStyle:
TextStyle
(
color:
Color
(
AppColors
.
hintText
)),
),
controller:
controller
,
);
}
}
}
\ No newline at end of file
netrain_flutter_app/lib/laishanqi/netrain/user/loginPage.dart
View file @
54d95d5c
...
@@ -6,7 +6,7 @@ import 'package:netrain_flutter_app/laishanqi/netrain/Http/HttpUtil.dart';
...
@@ -6,7 +6,7 @@ import 'package:netrain_flutter_app/laishanqi/netrain/Http/HttpUtil.dart';
import
'package:netrain_flutter_app/laishanqi/netrain/user/RegisterPage.dart'
;
import
'package:netrain_flutter_app/laishanqi/netrain/user/RegisterPage.dart'
;
import
'../HomePage.dart'
;
import
'../HomePage.dart'
;
import
'../Images.dart'
;
import
'../
../../common/
Images.dart'
;
/// 登录页
/// 登录页
class
LoginPage
extends
StatefulWidget
{
class
LoginPage
extends
StatefulWidget
{
...
@@ -22,10 +22,11 @@ class _LoginState extends State<LoginPage> {
...
@@ -22,10 +22,11 @@ class _LoginState extends State<LoginPage> {
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
print
(
"loginPage.dart initState"
);
var
mqtt
=
MqttClient
();
var
mqtt
=
MqttClient
();
mqtt
.
connect
();
mqtt
.
connect
();
HttpUtil
.
get
(
HttpUtil
.
global_config
).
then
((
Response
value
)
{
HttpUtil
.
get
(
HttpUtil
.
global_config
).
then
((
Response
value
)
{
Fluttertoast
.
showToast
(
msg:
"global_config 请求成功 "
);
Fluttertoast
.
showToast
(
msg:
"global_config 请求成功 "
);
});
});
...
@@ -107,7 +108,9 @@ class _LoginState extends State<LoginPage> {
...
@@ -107,7 +108,9 @@ class _LoginState extends State<LoginPage> {
children:
[
children:
[
MaterialButton
(
MaterialButton
(
onPressed:
()
{
onPressed:
()
{
Navigator
.
pushNamed
(
context
,
"register"
);
// 跳转到注册页,把手机号传递过去
Navigator
.
pushNamed
(
context
,
"register"
,
arguments:
[
phoneController
.
text
]);
// Navigator.push(context,MaterialPageRoute(builder: (context) => RegisterPage()));
// Navigator.push(context,MaterialPageRoute(builder: (context) => RegisterPage()));
},
},
child:
Text
(
child:
Text
(
...
@@ -116,7 +119,16 @@ class _LoginState extends State<LoginPage> {
...
@@ -116,7 +119,16 @@ class _LoginState extends State<LoginPage> {
),
),
),
),
Text
(
" | "
,
style:
TextStyle
(
color:
Colors
.
blue
)),
Text
(
" | "
,
style:
TextStyle
(
color:
Colors
.
blue
)),
Text
(
"忘记密码"
,
style:
TextStyle
(
color:
Colors
.
blue
))
MaterialButton
(
onPressed:
()
{
Navigator
.
pushNamed
(
context
,
"layout"
);
// Navigator.push(context,MaterialPageRoute(builder: (context) => RegisterPage()));
},
child:
Text
(
"忘记密码"
,
style:
TextStyle
(
color:
Colors
.
blue
),
),
),
],
],
),
),
),
),
...
...
netrain_flutter_app/lib/main.dart
View file @
54d95d5c
...
@@ -8,6 +8,7 @@ import 'laishanqi/layout_page.dart';
...
@@ -8,6 +8,7 @@ import 'laishanqi/layout_page.dart';
import
'laishanqi/netrain/user/loginPage.dart'
;
import
'laishanqi/netrain/user/loginPage.dart'
;
import
'laishanqi/netrain/user/RegisterPage.dart'
;
import
'laishanqi/netrain/user/RegisterPage.dart'
;
import
'laishanqi/photo.dart'
;
import
'laishanqi/photo.dart'
;
import
'zhangfeng/UserData.dart'
;
import
'zhangfeng/LoginPage.dart'
;
import
'zhangfeng/LoginPage.dart'
;
...
@@ -15,6 +16,7 @@ void main() {
...
@@ -15,6 +16,7 @@ void main() {
runApp
(
MyApp
());
runApp
(
MyApp
());
// runApp(Login());
// runApp(Login());
// runApp(TestPage());
// runApp(TestPage());
UserData
.
instance
;
print
(
"启动"
);
print
(
"启动"
);
}
}
...
@@ -22,34 +24,40 @@ class MyApp extends StatelessWidget {
...
@@ -22,34 +24,40 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
// This widget is the root of your application.
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
WillPopScope
(
child:
MaterialApp
(
return
WillPopScope
(
child:
MaterialApp
(
title:
'Flutter Demo'
,
title:
'Flutter Demo'
,
initialRoute:
"/
"
,
initialRoute:
"main
"
,
theme:
ThemeData
(
theme:
ThemeData
(
primarySwatch:
Colors
.
blue
,
primarySwatch:
Colors
.
blue
,
visualDensity:
VisualDensity
.
adaptivePlatformDensity
,
visualDensity:
VisualDensity
.
adaptivePlatformDensity
,
),
),
home:
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"路由"
),
),
body:
RouterNavigator
(
title:
'Flutter Demo Home Page'
),
),
routes:
<
String
,
WidgetBuilder
>{
routes:
<
String
,
WidgetBuilder
>{
"less"
:
(
context
)
=>
LessGroupPage
(),
"less"
:
(
context
)
=>
LessGroupPage
(),
"ful"
:
(
context
)
=>
FulGroupPage
(),
"ful"
:
(
context
)
=>
FulGroupPage
(),
"layout"
:
(
context
)
=>
LayoutPage
(),
"layout"
:
(
context
)
=>
LayoutPage
(),
"photo"
:
(
context
)
=>
PhotoApp
(),
"photo"
:
(
context
)
=>
PhotoApp
(),
"register"
:
(
context
)
=>
RegisterPage
(),
"register"
:
(
context
)
=>
RegisterPage
(),
"login"
:
(
context
)
=>
LoginPage
(),
"listPage"
:(
context
)
=>
List_Page
(),
"listPage"
:(
context
)
=>
List_Page
(),
"loginRequest"
:(
context
)
=>
LoginRequestPage
(),
"main"
:
(
context
)
=>
mainPage
(),
},
},
),
onWillPop:
()
async
{
),
onWillPop:
()
async
{
Fluttertoast
.
showToast
(
msg:
"退出"
);
Fluttertoast
.
showToast
(
msg:
"退出"
);
return
true
;
return
true
;
});
});
}
}
}
Widget
mainPage
(
){
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"路由"
),
),
body:
RouterNavigator
(
title:
'Flutter Demo Home Page'
),
);
}
}
class
RouterNavigator
extends
StatefulWidget
{
class
RouterNavigator
extends
StatefulWidget
{
...
@@ -61,7 +69,7 @@ class RouterNavigator extends StatefulWidget {
...
@@ -61,7 +69,7 @@ class RouterNavigator extends StatefulWidget {
}
}
class
_RouterNavigatorState
extends
State
<
RouterNavigator
>
{
class
_RouterNavigatorState
extends
State
<
RouterNavigator
>
{
bool
byName
=
fals
e
;
bool
byName
=
tru
e
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -90,13 +98,12 @@ class _RouterNavigatorState extends State<RouterNavigator> {
...
@@ -90,13 +98,12 @@ class _RouterNavigatorState extends State<RouterNavigator> {
_item
(
String
title
,
page
,
String
routeName
)
{
_item
(
String
title
,
page
,
String
routeName
)
{
return
Container
(
return
Container
(
child:
Rais
edButton
(
child:
Elevat
edButton
(
onPressed:
()
{
onPressed:
()
{
if
(
byName
)
{
if
(
byName
)
{
Navigator
.
pushNamed
(
context
,
routeName
);
Navigator
.
pushNamed
(
context
,
routeName
);
}
else
{
}
else
{
Navigator
.
push
(
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
page
,));
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
page
));
}
}
},
},
child:
Text
(
title
),
child:
Text
(
title
),
...
...
netrain_flutter_app/lib/xuehao/car_details.dart
0 → 100644
View file @
54d95d5c
import
'package:flutter/material.dart'
;
/**
* @author xuehao
* on 2021/7/9
*/
class
CarDetailsPage
extends
StatefulWidget
{
String
name
,
imageUrl
;
CarDetailsPage
({
Key
key
,
@required
this
.
name
,
@required
this
.
imageUrl
})
:
super
(
key:
key
);
@override
_CarDetailsState
createState
()
=>
_CarDetailsState
(
name
,
imageUrl
);
}
class
_CarDetailsState
extends
State
<
CarDetailsPage
>
{
String
name
,
imageUrl
;
_CarDetailsState
(
this
.
name
,
this
.
imageUrl
);
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
"car_details"
,
home:
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"汽车详情"
),
centerTitle:
true
,
leading:
new
IconButton
(
onPressed:
()
{
Navigator
.
pop
(
context
);
},
icon:
Icon
(
Icons
.
arrow_back_ios
)),
),
body:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Text
(
name
),
SizedBox
(
height:
40
),
Image
.
network
(
imageUrl
),
],
),
),
),
);
}
}
netrain_flutter_app/lib/xuehao/list_page.dart
View file @
54d95d5c
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_easyrefresh/easy_refresh.dart'
;
import
'package:flutter_easyrefresh/easy_refresh.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:netrain_flutter_app/xuehao/car_details.dart'
;
import
'Car.dart'
;
import
'Car.dart'
;
class
List_Page
extends
StatefulWidget
{
class
List_Page
extends
StatefulWidget
{
...
@@ -22,33 +23,45 @@ class _ListPageState extends State<List_Page> {
...
@@ -22,33 +23,45 @@ class _ListPageState extends State<List_Page> {
appBar:
AppBar
(
appBar:
AppBar
(
title:
Text
(
"ListView"
),
title:
Text
(
"ListView"
),
centerTitle:
true
,
centerTitle:
true
,
//leading 返回按键
//GestureDetector 用于事件触发
leading:
GestureDetector
(
leading:
GestureDetector
(
onTap:
()
{
onTap:
()
{
//当前页面出栈
Navigator
.
pop
(
context
);
Navigator
.
pop
(
context
);
},
},
//左上角返回的小箭头
child:
Icon
(
Icons
.
arrow_back_ios
),
child:
Icon
(
Icons
.
arrow_back_ios
),
),
),
),
),
body:
EasyRefresh
(
body:
EasyRefresh
(
header:
MaterialHeader
(),
//下拉刷新头布局、可以自定义
footer:
MaterialFooter
(),
header:
TaurusHeader
(),
//上拉加载尾布局,可以自定义
footer:
TaurusFooter
(),
enableControlFinishRefresh:
true
,
enableControlFinishRefresh:
true
,
enableControlFinishLoad:
true
,
enableControlFinishLoad:
true
,
//刷新和加载的控制器,用于控制刷新和加载
controller:
_controller
,
controller:
_controller
,
child:
ListView
.
builder
(
child:
ListView
.
builder
(
//返回数据条数
itemCount:
datas
.
length
,
itemCount:
datas
.
length
,
//itemBuilder 需要返回一个Widget
itemBuilder:
_getDatas
,
itemBuilder:
_getDatas
,
),
),
//刷新动作被触发
onRefresh:
()
async
{
onRefresh:
()
async
{
setState
(()
{
refreshData
();
refreshData
();
});
},
},
onLoad:
()
async
{},
//加载动作被触发
onLoad:
()
async
{
loadData
();
},
),
),
));
));
}
}
///获取item视图
Widget
_getDatas
(
BuildContext
context
,
int
position
)
{
Widget
_getDatas
(
BuildContext
context
,
int
position
)
{
return
Container
(
return
Container
(
child:
GestureDetector
(
child:
GestureDetector
(
...
@@ -73,18 +86,37 @@ class _ListPageState extends State<List_Page> {
...
@@ -73,18 +86,37 @@ class _ListPageState extends State<List_Page> {
onTap:
()
{
onTap:
()
{
var
data
=
datas
[
position
];
var
data
=
datas
[
position
];
Fluttertoast
.
showToast
(
msg:
"我点击了
${data.name}
"
);
Fluttertoast
.
showToast
(
msg:
"我点击了
${data.name}
"
);
Navigator
.
push
(
context
,
new
MaterialPageRoute
(
builder:
(
context
)
=>
new
CarDetailsPage
(
name:
data
.
name
,
imageUrl:
data
.
imageUrl
,)));
},
},
));
));
}
}
}
Future
<
void
>
refreshData
()
async
{
///刷新数据
Future
<
void
>
refreshData
()
async
{
await
Future
.
delayed
(
Duration
(
seconds:
3
),
()
{
await
Future
.
delayed
(
Duration
(
seconds:
3
),
()
{
setState
(()
{
for
(
int
i
=
0
;
i
<
datas
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
datas
.
length
;
i
++)
{
datas
[
i
].
name
=
"刷新后的数据
$i
"
;
datas
[
i
].
name
=
"刷新后的数据
$i
"
;
}
}
_controller
.
finishRefresh
(
success:
true
);
_controller
.
finishRefresh
(
success:
true
);
});
});
});
}
///加载数据
Future
<
void
>
loadData
()
async
{
await
Future
.
delayed
(
Duration
(
seconds:
3
),
()
{
setState
(()
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
datas
.
add
(
Car
(
name:
"新增数据
$i
"
,
imageUrl:
"https://img2.baidu.com/it/u=2010980676,2375641500&fm=11&fmt=auto&gp=0.jpg"
));
}
_controller
.
finishLoad
(
success:
true
);
});
});
}
}
}
//定义一个全局的变量:模型数组
//定义一个全局的变量:模型数组
...
...
netrain_flutter_app/lib/zhangfeng/LoginApi.dart
View file @
54d95d5c
import
'Network/HttpManager.dart'
;
import
'Network/HttpManager.dart'
;
import
'Network/BaseHttpModel.dart'
;
import
'Network/BaseHttpModel.dart'
;
import
'Network/UrlPath.dart'
;
import
'UserModel.dart'
;
import
'UserData.dart'
;
/// 所有接口类
/// 所有接口类
class
LoginApi
{
class
LoginApi
{
///示例请求
///示例请求
static
loginRequest
(
Map
<
String
,
dynamic
>
param
)
{
static
loginRequest
(
Map
<
String
,
dynamic
>
param
,
OnResult
onResult
)
{
return
HttpManager
.
getInstance
().
request
(
'auth/oauth/token'
,
parameters:
param
,
onResult:
(
data
,
errorMsg
){
return
HttpManager
.
getInstance
().
request
(
'auth/oauth/token'
,
parameters:
param
,
onResult:
(
data
,
errorMsg
){
BaseHttpModel
httpModel
=
data
;
BaseHttpModel
httpModel
=
data
;
print
(
httpModel
.
data
);
UserModel
userModel
=
UserModel
.
fromJson
(
httpModel
.
data
);
UserData
.
getInstance
().
saveUserModel
(
userModel
);
if
(
onResult
!=
null
){
onResult
(
data
,
errorMsg
);
}
});
});
}
}
}
}
netrain_flutter_app/lib/zhangfeng/LoginPage.dart
View file @
54d95d5c
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:netrain_flutter_app/zhangfeng/Network/HttpManager.dart'
;
import
'LoginApi.dart'
;
import
'LoginApi.dart'
;
import
'UserData.dart'
;
class
LoginRequestPage
extends
StatefulWidget
{
class
LoginRequestPage
extends
StatefulWidget
{
final
String
title
=
"登录页"
;
final
String
title
=
"登录页"
;
@override
@override
_LoginState
createState
()
=>
_LoginState
();
_LoginState
createState
()
=>
_LoginState
();
}
}
...
@@ -12,6 +14,10 @@ class LoginRequestPage extends StatefulWidget {
...
@@ -12,6 +14,10 @@ class LoginRequestPage extends StatefulWidget {
class
_LoginState
extends
State
<
LoginRequestPage
>
{
class
_LoginState
extends
State
<
LoginRequestPage
>
{
// This widget is the root of your application.
// This widget is the root of your application.
void
_loginAction
()
{
void
_loginAction
()
{
if
(
UserData
.
instance
.
userModel
!=
null
&&
UserData
.
instance
.
userModel
.
token
!=
null
){
Fluttertoast
.
showToast
(
msg:
'已经登录'
);
return
;
}
Map
<
String
,
String
>
map
=
new
Map
<
String
,
String
>();
Map
<
String
,
String
>
map
=
new
Map
<
String
,
String
>();
map
[
'workNumber'
]
=
'NTR000007'
;
map
[
'workNumber'
]
=
'NTR000007'
;
map
[
'password'
]
=
'123456'
;
map
[
'password'
]
=
'123456'
;
...
@@ -20,7 +26,17 @@ class _LoginState extends State<LoginRequestPage> {
...
@@ -20,7 +26,17 @@ class _LoginState extends State<LoginRequestPage> {
map
[
'client_id'
]
=
'app'
;
map
[
'client_id'
]
=
'app'
;
map
[
'client_secret'
]
=
'123456'
;
map
[
'client_secret'
]
=
'123456'
;
map
[
'platform'
]
=
'0'
;
map
[
'platform'
]
=
'0'
;
LoginApi
.
loginRequest
(
map
);
LoginApi
.
loginRequest
(
map
,
(
httpModel
,
error
){
if
(
error
!=
null
){
Fluttertoast
.
showToast
(
msg:
error
);
}
else
{
Fluttertoast
.
showToast
(
msg:
'登录成功'
);
}
});
}
void
_logoutAction
()
{
UserData
.
instance
.
removeUserModel
();
Fluttertoast
.
showToast
(
msg:
'退出成功'
);
}
}
@override
@override
...
@@ -37,6 +53,10 @@ class _LoginState extends State<LoginRequestPage> {
...
@@ -37,6 +53,10 @@ class _LoginState extends State<LoginRequestPage> {
onPressed:
_loginAction
,
onPressed:
_loginAction
,
child:
Icon
(
Icons
.
add
),
child:
Icon
(
Icons
.
add
),
),
),
FloatingActionButton
(
onPressed:
_logoutAction
,
child:
Icon
(
Icons
.
add
),
),
],
],
),
),
),
// This trailing comma makes auto-formatting nicer for build methods.
),
// This trailing comma makes auto-formatting nicer for build methods.
...
...
netrain_flutter_app/lib/zhangfeng/Network/BaseHttpModel.dart
View file @
54d95d5c
...
@@ -14,7 +14,7 @@ class BaseHttpModel{
...
@@ -14,7 +14,7 @@ class BaseHttpModel{
Map
<
String
,
dynamic
>
toJson
()
=>
_$BaseHttpModelToJson
(
this
);
Map
<
String
,
dynamic
>
toJson
()
=>
_$BaseHttpModelToJson
(
this
);
bool
isSuccess
(){
bool
isSuccess
(){
return
this
.
code
==
20
0
;
return
this
.
code
==
0
;
}
}
String
errorMsg
()
{
String
errorMsg
()
{
...
...
netrain_flutter_app/lib/zhangfeng/Network/HttpManager.dart
View file @
54d95d5c
...
@@ -3,6 +3,8 @@ import 'package:netrain_flutter_app/zhangfeng/Network/BaseHttpModel.dart';
...
@@ -3,6 +3,8 @@ import 'package:netrain_flutter_app/zhangfeng/Network/BaseHttpModel.dart';
import
'BaseHttpModel.dart'
;
import
'BaseHttpModel.dart'
;
import
'UrlPath.dart'
;
import
'UrlPath.dart'
;
typedef
OnResult
=
void
Function
(
BaseHttpModel
t
,
String
errorMsg
)
;
class
HttpManager
{
class
HttpManager
{
static
HttpManager
_instance
=
HttpManager
.
_internal
();
static
HttpManager
_instance
=
HttpManager
.
_internal
();
Dio
_dio
;
Dio
_dio
;
...
@@ -46,7 +48,7 @@ class HttpManager {
...
@@ -46,7 +48,7 @@ class HttpManager {
request
(
String
url
,
request
(
String
url
,
{
parameters
,
{
parameters
,
method
=
'GET'
,
method
=
'GET'
,
Function
(
BaseHttpModel
t
,
String
errorMsg
)
onResult
})
async
{
OnResult
onResult
})
async
{
parameters
=
parameters
??
{};
parameters
=
parameters
??
{};
if
(
onResult
==
null
){
if
(
onResult
==
null
){
return
;
return
;
...
@@ -55,7 +57,7 @@ class HttpManager {
...
@@ -55,7 +57,7 @@ class HttpManager {
Response
response
=
await
_dio
.
request
(
url
,
Response
response
=
await
_dio
.
request
(
url
,
queryParameters:
parameters
,
options:
new
Options
(
method:
method
));
queryParameters:
parameters
,
options:
new
Options
(
method:
method
));
BaseHttpModel
httpModel
=
BaseHttpModel
.
fromJson
(
response
.
data
);
BaseHttpModel
httpModel
=
BaseHttpModel
.
fromJson
(
response
.
data
);
if
(
httpModel
.
isSuccess
()
==
true
)
{
if
(
httpModel
.
isSuccess
())
{
onResult
(
httpModel
,
null
);
onResult
(
httpModel
,
null
);
}
else
{
}
else
{
onResult
(
httpModel
,
httpModel
.
errorMsg
());
onResult
(
httpModel
,
httpModel
.
errorMsg
());
...
...
netrain_flutter_app/lib/zhangfeng/UserData.dart
0 → 100644
View file @
54d95d5c
import
'dart:convert'
;
import
'UserModel.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
class
UserData
{
UserModel
userModel
;
factory
UserData
()
=>
getInstance
();
static
UserData
get
instance
=>
getInstance
();
static
UserData
_instance
;
static
UserData
getInstance
()
{
if
(
_instance
==
null
)
{
_instance
=
new
UserData
.
_internal
();
}
return
_instance
;
}
UserData
.
_internal
()
{
// 初始化
getUserModel
();
}
saveUserModel
(
UserModel
userModel
)
async
{
SharedPreferences
pref
=
await
SharedPreferences
.
getInstance
();
//将data转换成json字符串
var
jsonStr
=
json
.
encode
(
userModel
);
pref
.
setString
(
'UserModel'
,
jsonStr
);
this
.
userModel
=
userModel
;
}
// 读取 SharedPreferences
getUserModel
()
async
{
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
final
jsonStr
=
prefs
.
getString
(
'UserModel'
);
if
(
jsonStr
!=
null
&&
jsonStr
.
length
>
0
){
//先将json字符串转json
Map
json
=
jsonDecode
(
jsonStr
);
//将json转model
final
model
=
new
UserModel
.
fromJson
(
json
);
this
.
userModel
=
model
;
}
}
removeUserModel
()
async
{
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
prefs
.
setString
(
'UserModel'
,
""
);
this
.
userModel
=
null
;
}
}
\ No newline at end of file
netrain_flutter_app/lib/zhangfeng/UserModel.dart
0 → 100644
View file @
54d95d5c
import
'package:json_annotation/json_annotation.dart'
;
part
'UserModel.g.dart'
;
@JsonSerializable
()
class
UserModel
{
final
token
;
final
header
;
final
tokenHead
;
UserModel
(
this
.
token
,
this
.
header
,
this
.
tokenHead
);
factory
UserModel
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
=>
_$UserModelFromJson
(
json
);
Map
<
String
,
dynamic
>
toJson
()
=>
_$UserModelToJson
(
this
);
}
netrain_flutter_app/lib/zhangfeng/UserModel.g.dart
0 → 100644
View file @
54d95d5c
// GENERATED CODE - DO NOT MODIFY BY HAND
part of
'UserModel.dart'
;
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
UserModel
_$UserModelFromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
UserModel
(
json
[
'token'
],
json
[
'header'
],
json
[
'tokenHead'
],
);
}
Map
<
String
,
dynamic
>
_$UserModelToJson
(
UserModel
instance
)
=>
<
String
,
dynamic
>{
'token'
:
instance
.
token
,
'header'
:
instance
.
header
,
'tokenHead'
:
instance
.
tokenHead
,
};
netrain_flutter_app/pubspec.yaml
View file @
54d95d5c
...
@@ -42,7 +42,7 @@ dependencies:
...
@@ -42,7 +42,7 @@ dependencies:
dio
:
^4.0.0
#网络库
dio
:
^4.0.0
#网络库
convert
:
^3.0.1
#转码器
convert
:
^3.0.1
#转码器
pull_to_refresh
:
^2.0.0
pull_to_refresh
:
^2.0.0
shared_preferences
:
^2.0.6
dev_dependencies
:
dev_dependencies
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment