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
556ea774
Commit
556ea774
authored
Jul 13, 2021
by
“Icebear”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复saveModel不能同步获取数据的问题
parent
838d0fe1
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
14 deletions
+67
-14
main.dart
netrain_flutter_app/lib/main.dart
+4
-0
LoginApi.dart
netrain_flutter_app/lib/zhangfeng/LoginApi.dart
+1
-0
LoginPage.dart
netrain_flutter_app/lib/zhangfeng/LoginPage.dart
+2
-0
SaveModel.dart
netrain_flutter_app/lib/zhangfeng/Network/SaveModel.dart
+7
-10
TestPage.dart
netrain_flutter_app/lib/zhangfeng/TestPage.dart
+50
-0
UserModel.dart
netrain_flutter_app/lib/zhangfeng/UserModel.dart
+2
-3
pubspec.yaml
netrain_flutter_app/pubspec.yaml
+1
-1
No files found.
netrain_flutter_app/lib/main.dart
View file @
556ea774
import
'package:flutter/material.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:netrain_flutter_app/xuehao/list_page.dart'
;
import
'package:netrain_flutter_app/zhangfeng/TestPage.dart'
;
import
'laishanqi/Stateful_page.dart'
;
import
'laishanqi/Stateless_page.dart'
;
...
...
@@ -41,6 +42,7 @@ class MyApp extends StatelessWidget {
"login"
:
(
context
)
=>
LoginPage
(),
"listPage"
:(
context
)
=>
List_Page
(),
"LoginRequestPage"
:(
context
)
=>
LoginRequestPage
(),
"TestPage"
:
(
context
)
=>
SampleAppPage
(),
"main"
:
(
context
)
=>
mainPage
(),
},
),
...
...
@@ -90,7 +92,9 @@ class _RouterNavigatorState extends State<RouterNavigator> {
_item
(
"拍照页面"
,
PhotoApp
(),
'photo'
),
_item
(
"登陆"
,
LoginPage
(),
'login'
),
_item
(
"登录网络请求"
,
LoginRequestPage
(),
'LoginRequestPage'
),
_item
(
"zhangfengTest页面"
,
List_Page
(),
'TestPage'
),
_item
(
"listview页面"
,
List_Page
(),
'listPage'
),
],
),
);
...
...
netrain_flutter_app/lib/zhangfeng/LoginApi.dart
View file @
556ea774
...
...
@@ -10,6 +10,7 @@ class LoginApi {
BaseHttpModel
httpModel
=
data
;
UserModel
userModel
=
UserModel
.
fromJson
(
httpModel
.
data
);
UserModel
.
saveModel
(
userModel
);
print
(
UserModel
.
getModel
().
token
);
if
(
onResult
!=
null
){
onResult
(
data
,
errorMsg
);
}
...
...
netrain_flutter_app/lib/zhangfeng/LoginPage.dart
View file @
556ea774
...
...
@@ -51,10 +51,12 @@ class _LoginState extends State<LoginRequestPage> {
FloatingActionButton
(
onPressed:
_loginAction
,
child:
Icon
(
Icons
.
add
),
heroTag:
0
,
),
FloatingActionButton
(
onPressed:
_logoutAction
,
child:
Icon
(
Icons
.
add
),
heroTag:
1
,
),
],
),
...
...
netrain_flutter_app/lib/zhangfeng/Network/SaveModel.dart
View file @
556ea774
import
'dart:convert'
;
import
'package:
shared_preferences/shared_preference
s.dart'
;
import
'package:
flustars/flustar
s.dart'
;
class
SaveModel
{
// factory UserData() => getInstance();
...
...
@@ -17,17 +17,15 @@ class SaveModel {
//
// }
static
saveModel
(
dynamic
model
,
String
modelName
)
async
{
SharedPreferences
pref
=
await
SharedPreferences
.
getInstance
();
static
saveModel
(
dynamic
model
,
String
modelName
)
{
//将data转换成json字符串
var
jsonStr
=
json
.
encode
(
model
);
pref
.
setString
(
modelName
,
jsonStr
);
SpUtil
.
putString
(
modelName
,
jsonStr
);
}
// 读取 SharedPreferences
static
Future
<
Map
>
getModel
(
String
modelName
)
async
{
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
final
jsonStr
=
prefs
.
getString
(
modelName
);
static
getModel
(
String
modelName
)
{
final
jsonStr
=
SpUtil
.
getString
(
modelName
);
if
(
jsonStr
!=
null
&&
jsonStr
.
length
>
0
){
//先将json字符串转json
Map
json
=
jsonDecode
(
jsonStr
);
...
...
@@ -36,8 +34,7 @@ class SaveModel {
return
null
;
}
static
removeModel
(
String
modelName
)
async
{
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
prefs
.
setString
(
modelName
,
""
);
static
removeModel
(
String
modelName
){
SpUtil
.
putString
(
modelName
,
""
);
}
}
\ No newline at end of file
netrain_flutter_app/lib/zhangfeng/TestPage.dart
0 → 100644
View file @
556ea774
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
import
'package:dio/dio.dart'
;
import
'dart:convert'
;
class
SampleAppPage
extends
StatefulWidget
{
SampleAppPage
({
Key
key
})
:
super
(
key:
key
);
@override
_SampleAppPageState
createState
()
=>
_SampleAppPageState
();
}
class
_SampleAppPageState
extends
State
<
SampleAppPage
>{
String
_errorText
;
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"Sample App"
),
),
body:
Center
(
child:
TextField
(
onSubmitted:
(
String
text
)
{
setState
(()
{
if
(!
isEmail
(
text
))
{
_errorText
=
'Error: This is not an email'
;
}
else
{
_errorText
=
null
;
}
});
},
decoration:
InputDecoration
(
hintText:
"This is a hint"
,
errorText:
_getErrorText
()),
),
),
);
}
_getErrorText
()
{
return
_errorText
;
}
bool
isEmail
(
String
em
)
{
String
emailRegexp
=
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$'
;
RegExp
regExp
=
RegExp
(
emailRegexp
);
return
regExp
.
hasMatch
(
em
);
}
}
\ No newline at end of file
netrain_flutter_app/lib/zhangfeng/UserModel.dart
View file @
556ea774
...
...
@@ -19,11 +19,10 @@ class UserModel{
static
UserModel
getModel
(){
if
(
sharedModelInstance_
==
null
){
SaveModel
.
getModel
(
'UserModel'
).
then
((
json
)
=>
{
Map
json
=
SaveModel
.
getModel
(
'UserModel'
);
if
(
json
!=
null
){
sharedModelInstance_
=
new
UserModel
.
fromJson
(
json
)
sharedModelInstance_
=
new
UserModel
.
fromJson
(
json
)
;
}
});
}
return
sharedModelInstance_
;
}
...
...
netrain_flutter_app/pubspec.yaml
View file @
556ea774
...
...
@@ -42,7 +42,7 @@ dependencies:
dio
:
^4.0.0
#网络库
convert
:
^3.0.1
#转码器
pull_to_refresh
:
^2.0.0
shared_preferences
:
^2.0.6
flustars
:
^2.0.1
#强大的工具类库
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