Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
gmalpha_flutter
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
mobile
gmalpha_flutter
Commits
496de6de
Commit
496de6de
authored
Sep 05, 2019
by
林生雨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
0d25bc98
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
472 additions
and
39 deletions
+472
-39
local.properties
.android/local.properties
+2
-1
ServiceGenerator.dart
lib/Annotations/Generator/ServiceGenerator.dart
+41
-11
BaseModel.dart
lib/commonModel/live/BaseModel.dart
+14
-0
LiveData.dart
lib/commonModel/live/LiveData.dart
+27
-0
DioUtil.dart
lib/commonModel/net/DioUtil.dart
+2
-2
SimpleResponce.dart
lib/commonModel/net/Responce/SimpleResponce.dart
+26
-0
main.dart
lib/main.dart
+10
-5
UserRouter.dart
lib/userModel/UserRouter.dart
+3
-0
UserRouterImpl.dart
lib/userModel/UserRouterImpl.dart
+8
-4
UserPage.dart
lib/userModel/page/user/UserPage.dart
+112
-7
UserPageModel.dart
lib/userModel/page/user/UserPageModel.dart
+37
-2
UserRepository.dart
lib/userModel/service/UserRepository.dart
+30
-0
UserLocal.dart
lib/userModel/service/local/UserLocal.dart
+15
-0
UserRemote.dart
lib/userModel/service/remote/UserRemote.dart
+17
-0
UserLoginApi.dart
lib/userModel/service/remote/api/UserLoginApi.dart
+8
-2
UserLoginApi.serv.dart
lib/userModel/service/remote/api/UserLoginApi.serv.dart
+35
-5
TestUserEntity.dart
lib/userModel/service/remote/entity/TestUserEntity.dart
+85
-0
No files found.
.android/local.properties
View file @
496de6de
sdk.dir
=
/Users/apple/Library/Android/sdk
flutter.sdk
=
/Users/apple/Downloads/flutter
flutter.buildMode
=
release
flutter.buildMode
=
debug
flutter.versionName
=
1.0.0
flutter.versionCode
=
1
\ No newline at end of file
lib/Annotations/Generator/ServiceGenerator.dart
View file @
496de6de
...
...
@@ -31,21 +31,29 @@ class ServiceGenerator extends GeneratorForAnnotation<ServiceCenter> {
final
metadata
=
annometadata
.
computeConstantValue
();
if
(
metadata
.
type
.
name
==
"Post"
||
metadata
.
type
.
name
==
"Get"
)
{
if
(!
differentList
.
contains
(
methodElement
.
returnType
.
name
))
{
var
pathSegments
=
buildStep
.
inputId
.
pathSegments
;
StringBuffer
path
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
pathSegments
.
length
;
i
++)
{
if
(
i
<
pathSegments
.
length
-
2
&&
pathSegments
[
i
]
!=
"lib"
)
{
path
.
write
(
"
${pathSegments[i]}
/"
);
if
(
methodElement
.
returnType
.
name
==
"SimpleResponce"
){
improtBuffer
.
write
(
"import 'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart';
\n
"
);
}
else
{
var
pathSegments
=
buildStep
.
inputId
.
pathSegments
;
StringBuffer
path
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
pathSegments
.
length
;
i
++)
{
if
(
i
<
pathSegments
.
length
-
2
&&
pathSegments
[
i
]
!=
"lib"
)
{
path
.
write
(
"
${pathSegments[i]}
/"
);
}
}
improtBuffer
.
write
(
"import 'package:
${buildStep.inputId.package}
/
${path
.toString()}
entity/
${methodElement.returnType
.name}
.dart
\'
;
\n
"
);
}
improtBuffer
.
write
(
"import 'package:
${buildStep.inputId.package}
/
${path.toString()}
entity/
${methodElement.returnType.name}
.dart
\'
;
\n
"
);
differentList
.
add
(
methodElement
.
returnType
.
name
);
}
String
tempParams
;
String
sendType
=
metadata
.
type
.
name
==
"Post"
?
"post"
:
"get"
;
mapBuffer
.
write
(
"""
return Observable.fromFuture(DioUtil().
${sendType}
(
\'
${metadata.getField("sufUrl").toStringValue()}
\'
,data:{
return Observable.fromFuture(DioUtil().
${sendType}
(
\'
${metadata.getField("sufUrl").toStringValue()}
\'
"""
);
bool
needMap
=
false
;
for
(
int
i
=
0
;
i
<
methodElement
.
parameters
.
length
;
i
++)
{
...
...
@@ -60,9 +68,17 @@ class ServiceGenerator extends GeneratorForAnnotation<ServiceCenter> {
}
else
{
tempParams
=
"
${tempParams}
,
${paramsMeta}
"
;
}
if
(
i
==
methodElement
.
parameters
.
length
-
1
)
{
if
(
i
==
0
)
{
mapBuffer
.
write
(
"
\'
${queryAnno.getField("params").toStringValue()}
\'
:
${paramsMeta.name}
"
);
",data:{
\'
${queryAnno.getField("params").toStringValue()}
\'
:
${paramsMeta.name}
"
);
if
(
methodElement
.
parameters
.
length
>
1
){
mapBuffer
.
write
(
","
);
}
else
{
mapBuffer
.
write
(
"}"
);
}
}
else
if
(
i
==
methodElement
.
parameters
.
length
-
1
)
{
mapBuffer
.
write
(
"
\'
${queryAnno.getField("params").toStringValue()}
\'
:
${paramsMeta.name}
}"
);
}
else
{
mapBuffer
.
write
(
"
\'
${queryAnno.getField("params").toStringValue()}
\'
:
${paramsMeta.name}
,"
);
...
...
@@ -70,7 +86,7 @@ class ServiceGenerator extends GeneratorForAnnotation<ServiceCenter> {
}
}
}
mapBuffer
.
write
(
"
}
))"
);
mapBuffer
.
write
(
"))"
);
mapBuffer
.
write
(
"""
.map((value){
if(value.statusCode==200){
...
...
@@ -98,6 +114,20 @@ class ServiceGenerator extends GeneratorForAnnotation<ServiceCenter> {
${improtBuffer.toString()}
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';
\n
class
${element.displayName}
Impl{
factory
${element.displayName}
Impl() => _sharedInstance();
static
${element.displayName}
Impl _instance;
${element.displayName}
Impl._() {
}
static
${element.displayName}
Impl _sharedInstance() {
if (_instance == null) {
_instance =
${element.displayName}
Impl._();
}
return _instance;
}
${methodBuffer.toString()}
}
"""
;
...
...
lib/commonModel/live/BaseModel.dart
0 → 100644
View file @
496de6de
/*
* @author lsy
* @date 2019-09-05
**/
import
'dart:async'
;
import
'package:rxdart/rxdart.dart'
;
abstract
class
BaseModel
{
//TODO
void
dispose
();
}
lib/commonModel/live/LiveData.dart
0 → 100644
View file @
496de6de
/*
* @author lsy
* @date 2019-09-05
**/
import
'dart:async'
;
class
LiveData
<
T
>
{
StreamController
<
T
>
_controller
;
T
data
;
LiveData
()
{
this
.
_controller
=
new
StreamController
<
T
>();
}
get
stream
=>
_controller
.
stream
;
get
controller
=>
_controller
;
void
notifyView
(
T
t
)
{
this
.
data
=
t
;
_controller
.
sink
.
add
(
t
);
}
void
dispost
()
{
_controller
.
close
();
}
}
lib/commonModel/net/DioUtil.dart
View file @
496de6de
...
...
@@ -255,12 +255,12 @@ class DioUtil {
/*
* post请求
*/
post
(
url
,
{
data
,
options
,
cancelToken
})
async
{
Future
<
Response
>
post
(
url
,
{
data
,
options
,
cancelToken
})
async
{
Response
response
;
try
{
response
=
await
_dio
.
post
(
url
,
queryParameters:
data
,
options:
options
,
cancelToken:
cancelToken
);
print
(
'post success---------
${response.data}
'
);
print
(
'post success---------
${response.
statusCode}
${response.
data}
'
);
}
on
DioError
catch
(
e
)
{
print
(
'post error---------
$e
'
);
formatError
(
e
);
...
...
lib/commonModel/net/Responce/SimpleResponce.dart
0 → 100644
View file @
496de6de
/*
* @author lsy
* @date 2019-09-05
**/
class
SimpleResponce
{
Null
data
;
int
errorCode
;
String
errorMsg
;
SimpleResponce
({
this
.
data
,
this
.
errorCode
,
this
.
errorMsg
});
SimpleResponce
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
data
=
json
[
'data'
];
errorCode
=
json
[
'errorCode'
];
errorMsg
=
json
[
'errorMsg'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
new
Map
<
String
,
dynamic
>();
data
[
'data'
]
=
this
.
data
;
data
[
'errorCode'
]
=
this
.
errorCode
;
data
[
'errorMsg'
]
=
this
.
errorMsg
;
return
data
;
}
}
\ No newline at end of file
lib/main.dart
View file @
496de6de
...
...
@@ -56,11 +56,16 @@ class _MyAppState extends State<MyApp> {
routes:
{
// '/': (context) => CommentSuggest({"Cookie":" _gm_token=7e48641558699683; sessionid=nb3ze4ur7ucosln8sd8pzwojddenv9ym; _gtid=a1bc0a387e1911e996b9525400fa516d4094"}),
'/'
:
(
context
)
{
var
findMessageRouter
=
RouterCenterImpl
().
findMessageRouter
();
if
(
findMessageRouter
==
null
)
{
return
null
;
}
return
findMessageRouter
.
getMessagePage
({});
// var findMessageRouter = RouterCenterImpl().findMessageRouter();
// if (findMessageRouter == null) {
// return null;
// }
// return findMessageRouter.getMessagePage({});
var
findUserRouter
=
RouterCenterImpl
().
findUserRouter
();
if
(
findUserRouter
==
null
){
return
null
;
}
return
findUserRouter
.
getUserPage
();
},
},
//调试的时候可以打开
...
...
lib/userModel/UserRouter.dart
View file @
496de6de
...
...
@@ -3,6 +3,7 @@
* @date 2019-09-03
**/
import
'package:flutter/material.dart'
;
import
'package:gmalpha_flutter/Annotations/RouterBaser.dart'
;
import
'package:gmalpha_flutter/Annotations/anno/Router.dart'
;
import
'package:gmalpha_flutter/userModel/UserRouterImpl.dart'
;
...
...
@@ -10,4 +11,5 @@ import 'package:gmalpha_flutter/userModel/UserRouterImpl.dart';
@Router
(
"userModel"
,
UserRouterImpl
)
abstract
class
UserRouter
implements
RouterBaser
{
Widget
getUserPage
();
}
\ No newline at end of file
lib/userModel/UserRouterImpl.dart
View file @
496de6de
...
...
@@ -2,8 +2,13 @@
* @author lsy
* @date 2019-09-03
**/
import
'package:flutter/src/widgets/framework.dart'
;
import
'package:gmalpha_flutter/userModel/UserRouter.dart'
;
import
'package:gmalpha_flutter/userModel/page/user/UserPage.dart'
;
class
UserRouterImpl
implements
UserRouter
{
}
\ No newline at end of file
class
UserRouterImpl
implements
UserRouter
{
@override
Widget
getUserPage
()
{
return
UserWidget
();
}
}
lib/userModel/page/user/UserPage.dart
View file @
496de6de
...
...
@@ -2,8 +2,12 @@
* @author lsy
* @date 2019-09-04
**/
import
'package:flutter/material.dart'
;
import
'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart'
;
import
'package:gmalpha_flutter/userModel/page/user/UserPageModel.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/TestUserEntity.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart'
;
class
UserWidget
extends
StatefulWidget
{
@override
...
...
@@ -13,20 +17,121 @@ class UserWidget extends StatefulWidget {
class
UserState
extends
State
<
UserWidget
>
{
UserPageModel
_model
;
TextEditingController
_nameController
=
new
TextEditingController
();
TextEditingController
_wordController
=
new
TextEditingController
();
@override
void
initState
()
{
super
.
initState
();
_model
=
new
UserPageModel
();
}
@override
void
dispose
()
{
super
.
dispose
();
_model
.
dispose
();
_wordController
.
dispose
();
_nameController
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
// return Scaffold(
// body: ALRootInheritWideget(
// model: _model,
// child: Center(
// child: Text(_model.text),
// ),
// ));
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"User"
,
style:
TextStyle
(
fontSize:
16
),
),
centerTitle:
true
,
),
body:
Column
(
children:
<
Widget
>[
Expanded
(
child:
StreamBuilder
<
SimpleResponce
>(
stream:
_model
.
logoutLive
.
stream
,
initialData:
_model
.
logoutLive
.
data
,
builder:
(
BuildContext
context
,
AsyncSnapshot
<
SimpleResponce
>
snapshot
)
{
if
(
snapshot
.
data
==
null
)
{
return
Center
(
child:
Text
(
"没有退出"
));
}
else
{
return
Center
(
child:
Text
(
"退出接口回掉成功!!"
));
}
},
),
),
Container
(
margin:
EdgeInsets
.
fromLTRB
(
16
,
10
,
16
,
20
),
child:
TextField
(
cursorColor:
Colors
.
black
,
controller:
_nameController
,
decoration:
InputDecoration
(
contentPadding:
EdgeInsets
.
all
(
10.0
),
icon:
Icon
(
Icons
.
text_fields
,
color:
Colors
.
black
),
labelText:
'name'
,
labelStyle:
TextStyle
(
color:
Colors
.
black
)),
autofocus:
false
,
),
),
Container
(
margin:
EdgeInsets
.
fromLTRB
(
16
,
0
,
16
,
20
),
child:
TextField
(
cursorColor:
Colors
.
black
,
controller:
_wordController
,
decoration:
InputDecoration
(
contentPadding:
EdgeInsets
.
all
(
10.0
),
icon:
Icon
(
Icons
.
text_fields
,
color:
Colors
.
black
,
),
labelText:
'word'
,
labelStyle:
TextStyle
(
color:
Colors
.
black
)),
autofocus:
false
,
),
),
Container
(
width:
double
.
maxFinite
,
margin:
EdgeInsets
.
fromLTRB
(
16
,
0
,
16
,
0
),
child:
OutlineButton
(
onPressed:
()
=>
_model
.
resignUser
(
context
,
_nameController
.
text
,
_wordController
.
text
),
child:
Text
(
"注册"
),
shape:
BeveledRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
3
),
),
)),
Container
(
width:
double
.
maxFinite
,
margin:
EdgeInsets
.
fromLTRB
(
16
,
0
,
16
,
0
),
child:
OutlineButton
(
onPressed:
()
=>
_model
.
logout
(
context
),
child:
Text
(
"退出"
),
shape:
BeveledRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
3
),
),
)),
Expanded
(
child:
StreamBuilder
<
TestUserEntity
>(
stream:
_model
.
resignLive
.
stream
,
initialData:
_model
.
resignLive
.
data
,
builder:
(
BuildContext
context
,
AsyncSnapshot
<
TestUserEntity
>
snapshot
)
{
if
(
snapshot
.
data
!=
null
)
{
return
Center
(
child:
snapshot
.
data
.
data
==
null
?
Text
(
"错误
${snapshot.data.errorMsg}
"
)
:
Text
(
"登入回掉 用户id:
${snapshot.data.data.id}
"
),
);
}
else
{
return
Center
(
child:
Text
(
"初始化~"
),
);
}
},
),
)
],
),
);
}
}
lib/userModel/page/user/UserPageModel.dart
View file @
496de6de
...
...
@@ -3,11 +3,46 @@
* @date 2019-09-04
**/
class
UserPageModel
{
import
'package:flutter/cupertino.dart'
;
import
'package:gmalpha_flutter/commonModel/live/BaseModel.dart'
;
import
'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart'
;
import
'package:gmalpha_flutter/commonModel/toast/toast.dart'
;
import
'package:gmalpha_flutter/userModel/service/UserRepository.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/TestUserEntity.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart'
;
String
text
;
import
'../../../commonModel/live/LiveData.dart'
;
class
UserPageModel
extends
BaseModel
{
LiveData
<
SimpleResponce
>
logoutLive
=
new
LiveData
();
LiveData
<
TestUserEntity
>
resignLive
=
new
LiveData
();
// LiveData<String> userTokenLive = new LiveData();
UserPageModel
()
{}
void
logout
(
BuildContext
context
)
{
UserRepository
.
getInstance
().
logout
().
listen
((
data
)
{
logoutLive
.
notifyView
(
data
);
}).
onError
((
error
)
{
Toast
.
show
(
context
,
"error
${error}
"
);
print
(
error
);
});
}
void
resignUser
(
BuildContext
context
,
String
name
,
String
word
)
{
UserRepository
.
getInstance
().
resignUser
(
name
,
word
,
word
).
listen
((
data
)
{
print
(
"data !! :
${data}
"
);
resignLive
.
notifyView
(
data
);
}).
onError
((
error
)
{
Toast
.
show
(
context
,
"error :
${error}
"
);
print
(
error
);
});
}
@override
void
dispose
()
{
logoutLive
.
dispost
();
resignLive
.
dispost
();
}
}
lib/userModel/service/UserRepository.dart
View file @
496de6de
...
...
@@ -2,8 +2,12 @@
* @author lsy
* @date 2019-09-04
**/
import
'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart'
;
import
'package:gmalpha_flutter/userModel/service/local/UserLocal.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/UserRemote.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/TestUserEntity.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart'
;
import
'package:rxdart/rxdart.dart'
;
class
UserRepository
{
UserRemote
_remote
;
...
...
@@ -23,5 +27,31 @@ class UserRepository {
return
_userRepository
;
}
Observable
<
UserEntity
>
getUserInfo
(
String
token
)
{
_remote
.
getUserInfo
(
token
).
map
((
value
)
{
if
(
value
!=
null
)
{
_local
.
saveUserInfo
(
value
);
}
return
value
;
});
}
Observable
<
TestUserEntity
>
resignUser
(
String
name
,
String
word
,
String
reword
)
{
return
_remote
.
resignUser
(
name
,
word
,
reword
).
map
((
value
)
{
if
(
value
!=
null
)
{
_local
.
saveUser
(
value
);
}
return
value
;
});
}
Observable
<
SimpleResponce
>
logout
()
{
return
_remote
.
logout
().
map
((
value
)
{
if
(
value
!=
null
)
{
_local
.
logout
();
}
return
value
;
});
}
}
lib/userModel/service/local/UserLocal.dart
View file @
496de6de
...
...
@@ -2,6 +2,9 @@
* @author lsy
* @date 2019-09-04
**/
import
'package:gmalpha_flutter/userModel/service/remote/entity/TestUserEntity.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart'
;
class
UserLocal
{
static
UserLocal
_userRemote
;
...
...
@@ -13,4 +16,16 @@ class UserLocal {
}
return
_userRemote
;
}
void
saveUserInfo
(
UserEntity
value
)
{
//TODO
}
void
saveUser
(
TestUserEntity
value
)
{
//TODO
}
void
logout
()
{
//TODO
}
}
lib/userModel/service/remote/UserRemote.dart
View file @
496de6de
...
...
@@ -2,6 +2,12 @@
* @author lsy
* @date 2019-09-04
**/
import
'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/api/UserLoginApi.serv.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/TestUserEntity.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart'
;
import
'package:rxdart/rxdart.dart'
;
class
UserRemote
{
static
UserRemote
_userRemote
;
...
...
@@ -14,5 +20,16 @@ class UserRemote {
return
_userRemote
;
}
Observable
<
UserEntity
>
getUserInfo
(
String
token
)
{
return
UserLoginApiImpl
().
getUserInfo
(
token
);
}
Observable
<
TestUserEntity
>
resignUser
(
String
name
,
String
word
,
String
reWord
)
{
return
UserLoginApiImpl
().
resign
(
name
,
word
,
reWord
);
}
Observable
<
SimpleResponce
>
logout
()
{
return
UserLoginApiImpl
().
logout
();
}
}
lib/userModel/service/remote/api/UserLoginApi.dart
View file @
496de6de
...
...
@@ -6,13 +6,19 @@ import 'package:gmalpha_flutter/Annotations/anno/Get.dart';
import
'package:gmalpha_flutter/Annotations/anno/Post.dart'
;
import
'package:gmalpha_flutter/Annotations/anno/Query.dart'
;
import
'package:gmalpha_flutter/Annotations/anno/ServiceCenter.dart'
;
import
'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/TestUserEntity.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart'
;
@ServiceCenter
()
abstract
class
UserLoginApi
{
@Post
(
"user/login"
)
UserEntity
login
(
@Query
(
"name"
)
String
name
,
@Query
(
"word"
)
String
word
);
@Post
(
"user/register"
)
TestUserEntity
resign
(
@Query
(
"username"
)
String
name
,
@Query
(
"password"
)
String
word
,
@Query
(
"repassword"
)
String
repassword
);
@Get
(
"user/info"
)
UserEntity
getUserInfo
(
@Query
(
"token"
)
String
token
);
@Get
(
"user/logout/json"
)
SimpleResponce
logout
();
}
lib/userModel/service/remote/api/UserLoginApi.serv.dart
View file @
496de6de
...
...
@@ -10,18 +10,36 @@ import 'dart:io';
import
'package:rxdart/rxdart.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/TestUserEntity.dart'
;
import
'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart'
;
import
'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart'
;
import
'package:gmalpha_flutter/commonModel/net/DioUtil.dart'
;
class
UserLoginApiImpl
{
Observable
<
UserEntity
>
login
(
String
name
,
String
word
)
{
return
Observable
.
fromFuture
(
DioUtil
().
post
(
'user/login'
,
data:
{
'name'
:
name
,
'word'
:
word
}))
.
map
((
value
)
{
factory
UserLoginApiImpl
()
=>
_sharedInstance
();
static
UserLoginApiImpl
_instance
;
UserLoginApiImpl
.
_
()
{}
static
UserLoginApiImpl
_sharedInstance
()
{
if
(
_instance
==
null
)
{
_instance
=
UserLoginApiImpl
.
_
();
}
return
_instance
;
}
Observable
<
TestUserEntity
>
resign
(
String
name
,
String
word
,
String
repassword
)
{
return
Observable
.
fromFuture
(
DioUtil
().
post
(
'user/register'
,
data:
{
'username'
:
name
,
'password'
:
word
,
'repassword'
:
repassword
})).
map
((
value
)
{
if
(
value
.
statusCode
==
200
)
{
Map
map
=
json
.
decode
(
value
.
toString
());
return
UserEntity
.
fromJson
(
map
);
return
Test
UserEntity
.
fromJson
(
map
);
}
else
{
throw
HttpException
(
"statusCode error :
${value.statusCode}
"
);
}
...
...
@@ -39,4 +57,16 @@ class UserLoginApiImpl {
}
});
}
Observable
<
SimpleResponce
>
logout
()
{
return
Observable
.
fromFuture
(
DioUtil
().
get
(
'user/logout/json'
))
.
map
((
value
)
{
if
(
value
.
statusCode
==
200
)
{
Map
map
=
json
.
decode
(
value
.
toString
());
return
SimpleResponce
.
fromJson
(
map
);
}
else
{
throw
HttpException
(
"statusCode error :
${value.statusCode}
"
);
}
});
}
}
lib/userModel/service/remote/entity/TestUserEntity.dart
0 → 100644
View file @
496de6de
/*
* @author lsy
* @date 2019-09-05
**/
class
TestUserEntity
{
Data
data
;
int
errorCode
;
String
errorMsg
;
TestUserEntity
({
this
.
data
,
this
.
errorCode
,
this
.
errorMsg
});
TestUserEntity
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
data
=
json
[
'data'
]
!=
null
?
new
Data
.
fromJson
(
json
[
'data'
])
:
null
;
errorCode
=
json
[
'errorCode'
];
errorMsg
=
json
[
'errorMsg'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
new
Map
<
String
,
dynamic
>();
if
(
this
.
data
!=
null
)
{
data
[
'data'
]
=
this
.
data
.
toJson
();
}
data
[
'errorCode'
]
=
this
.
errorCode
;
data
[
'errorMsg'
]
=
this
.
errorMsg
;
return
data
;
}
}
class
Data
{
bool
admin
;
List
<
String
>
chapterTops
;
List
<
String
>
collectIds
;
String
email
;
String
icon
;
int
id
;
String
nickname
;
String
password
;
String
token
;
int
type
;
String
username
;
Data
(
{
this
.
admin
,
this
.
chapterTops
,
this
.
collectIds
,
this
.
email
,
this
.
icon
,
this
.
id
,
this
.
nickname
,
this
.
password
,
this
.
token
,
this
.
type
,
this
.
username
});
Data
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
admin
=
json
[
'admin'
];
chapterTops
=
json
[
'chapterTops'
].
cast
<
String
>();
collectIds
=
json
[
'collectIds'
].
cast
<
String
>();
email
=
json
[
'email'
];
icon
=
json
[
'icon'
];
id
=
json
[
'id'
];
nickname
=
json
[
'nickname'
];
password
=
json
[
'password'
];
token
=
json
[
'token'
];
type
=
json
[
'type'
];
username
=
json
[
'username'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
new
Map
<
String
,
dynamic
>();
data
[
'admin'
]
=
this
.
admin
;
data
[
'chapterTops'
]
=
this
.
chapterTops
;
data
[
'collectIds'
]
=
this
.
collectIds
;
data
[
'email'
]
=
this
.
email
;
data
[
'icon'
]
=
this
.
icon
;
data
[
'id'
]
=
this
.
id
;
data
[
'nickname'
]
=
this
.
nickname
;
data
[
'password'
]
=
this
.
password
;
data
[
'token'
]
=
this
.
token
;
data
[
'type'
]
=
this
.
type
;
data
[
'username'
]
=
this
.
username
;
return
data
;
}
}
\ No newline at end of file
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