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
9c0e86b5
Commit
9c0e86b5
authored
Jul 22, 2021
by
窦文
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http
parent
bb56d287
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
226 additions
and
9 deletions
+226
-9
Demo2.dart
netrain_flutter_app/lib/douwen/Demo2.dart
+7
-2
BaseViewModel.dart
netrain_flutter_app/lib/douwen/custom/BaseViewModel.dart
+11
-0
AdRepository.dart
netrain_flutter_app/lib/douwen/custom/http/AdRepository.dart
+22
-0
AdService.dart
netrain_flutter_app/lib/douwen/custom/http/AdService.dart
+18
-0
ApiException.dart
...flutter_app/lib/douwen/custom/http/base/ApiException.dart
+9
-0
ErrorInterceptor.dart
...ter_app/lib/douwen/custom/http/base/ErrorInterceptor.dart
+18
-0
HttpCode.dart
...ain_flutter_app/lib/douwen/custom/http/base/HttpCode.dart
+5
-0
HttpUtil.dart
...ain_flutter_app/lib/douwen/custom/http/base/HttpUtil.dart
+14
-0
IEntity.dart
netrain_flutter_app/lib/douwen/custom/http/base/IEntity.dart
+55
-0
IRepository.dart
..._flutter_app/lib/douwen/custom/http/base/IRepository.dart
+14
-0
IService.dart
...ain_flutter_app/lib/douwen/custom/http/base/IService.dart
+46
-0
DoctorHomePage.dart
...ain_flutter_app/lib/laishanqi/netrain/DoctorHomePage.dart
+7
-7
No files found.
netrain_flutter_app/lib/douwen/Demo2.dart
View file @
9c0e86b5
import
'package:dio/dio.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/src/widgets/framework.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:netrain_flutter_app/douwen/custom/BaseView.dart'
;
import
'package:netrain_flutter_app/douwen/custom/BaseViewModel.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/AdService.dart'
;
import
'custom/http/base/IEntity.dart'
;
class
Demo2
extends
BaseView
{
...
...
@@ -30,8 +35,8 @@ class Demo2 extends BaseView {
builder:
(
context
,
value
,
child
)
=>
Text
(
"点击了
${viewModel.num.value}
次"
)),
ElevatedButton
(
onPressed:
()
{
viewModel
.
click
();
onPressed:
()
async
{
viewModel
.
login
();
},
child:
Text
(
"点击"
))
],
...
...
netrain_flutter_app/lib/douwen/custom/BaseViewModel.dart
View file @
9c0e86b5
import
'package:flutter/widgets.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/AdRepository.dart'
;
import
'ViewState.dart'
;
...
...
@@ -7,6 +9,7 @@ class BaseViewModel extends ChangeNotifier {
var
num
=
ValueNotifier
<
int
>(
0
);
set
viewState
(
ViewState
viewState
)
=>
setViewState
(
viewState
);
get
viewState
=>
_viewState
;
void
click
()
{
...
...
@@ -37,4 +40,12 @@ class BaseViewModel extends ChangeNotifier {
_viewState
=
viewState
;
notifyListeners
();
}
void
login
()
{
AdRepository
.
instance
.
login
((
str
)
{
Fluttertoast
.
showToast
(
msg:
str
);
},
(
iEntity
)
{
Fluttertoast
.
showToast
(
msg:
iEntity
.
msg
);
});
}
}
netrain_flutter_app/lib/douwen/custom/http/AdRepository.dart
0 → 100644
View file @
9c0e86b5
import
'package:netrain_flutter_app/douwen/custom/http/AdService.dart'
;
import
'base/IEntity.dart'
;
import
'base/IRepository.dart'
;
class
AdRepository
with
IRepository
{
AdRepository
.
_privateConstructor
(
this
.
_service
);
static
AdRepository
_instance
;
static
AdRepository
get
instance
{
if
(
_instance
==
null
)
{
_instance
=
AdRepository
.
_privateConstructor
(
AdService
());
}
return
_instance
;
}
final
AdService
_service
;
void
login
(
void
onSuccess
(
String
str
),
void
onError
(
IEntity
iEntity
))
=>
getResult
<
String
>(
_service
.
login
(),
analysis:
(
data
)
=>
data
.
toString
(),
onSuccess:
(
str
)
=>
onSuccess
(
str
),
onError:
(
iEntity
)
=>
onError
(
iEntity
));
}
netrain_flutter_app/lib/douwen/custom/http/AdService.dart
0 → 100644
View file @
9c0e86b5
import
'package:dio/dio.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/base/IService.dart'
;
import
'base/IEntity.dart'
;
class
AdService
with
IService
{
@override
String
getServicePath
()
{
return
"/ad"
;
}
Future
<
IEntity
>
login
()
=>
post
(
"/login/validLogin"
,
{
"phoneNum"
:
"15321350450"
,
"verifyCode"
:
"123456"
,
"deviceSN"
:
"123456"
});
}
netrain_flutter_app/lib/douwen/custom/http/base/ApiException.dart
0 → 100644
View file @
9c0e86b5
import
'IEntity.dart'
;
class
ApiException
implements
Exception
{
IEntity
_iEntity
;
get
iEntity
=>
_iEntity
;
ApiException
(
this
.
_iEntity
){}
}
\ No newline at end of file
netrain_flutter_app/lib/douwen/custom/http/base/ErrorInterceptor.dart
0 → 100644
View file @
9c0e86b5
import
'package:dio/dio.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/base/HttpCode.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/base/IEntity.dart'
;
import
'ApiException.dart'
;
class
ErrorInterceptor
extends
Interceptor
{
@override
void
onResponse
(
Response
response
,
ResponseInterceptorHandler
handler
)
{
IEntity
iEntity
=
IEntity
.
fromJson
(
response
.
data
);
if
(
HttpCode
.
SUCCESS
!=
iEntity
.
code
)
{
throw
ApiException
(
iEntity
);
}
response
.
data
=
iEntity
;
return
super
.
onResponse
(
response
,
handler
);
}
}
\ No newline at end of file
netrain_flutter_app/lib/douwen/custom/http/base/HttpCode.dart
0 → 100644
View file @
9c0e86b5
class
HttpCode
{
static
int
SUCCESS
=
0
;
static
int
NORMAL_ERROR
=
-
999
;
//非逻辑错误码(网络错误、超时等)
}
\ No newline at end of file
netrain_flutter_app/lib/douwen/custom/http/base/HttpUtil.dart
0 → 100644
View file @
9c0e86b5
import
'package:dio/dio.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/base/ErrorInterceptor.dart'
;
class
HttpUtil
{
static
String
baseUrl
=
"https://api.hkmeinian-hlw.cn"
;
Dio
getDio
(
String
baseUrl
){
return
Dio
(
BaseOptions
(
baseUrl:
baseUrl
,
))
..
interceptors
.
add
(
ErrorInterceptor
());
}
}
netrain_flutter_app/lib/douwen/custom/http/base/IEntity.dart
0 → 100644
View file @
9c0e86b5
import
'package:netrain_flutter_app/douwen/custom/http/base/HttpCode.dart'
;
/// code : -1
/// msg : "系统繁忙!"
/// data : null
/// timestamp : "2021-07-21 15:29:05"
class
IEntity
<
T
>
{
int
_code
;
String
_msg
;
dynamic
_data
;
String
_timestamp
;
int
get
code
=>
_code
;
set
code
(
int
code
)
=>
_code
=
code
;
String
get
msg
=>
_msg
;
set
msg
(
String
msg
)
=>
_msg
=
msg
;
dynamic
get
data
=>
_data
;
String
get
timestamp
=>
_timestamp
;
set
timestamp
(
String
msg
)
=>
_timestamp
=
msg
;
IEntity
({
int
code
,
String
msg
,
dynamic
data
,
String
timestamp
})
{
_code
=
code
;
_msg
=
msg
;
_data
=
data
;
_timestamp
=
timestamp
;
}
bool
isSuccess
(){
if
(
code
==
HttpCode
.
SUCCESS
)
{
return
true
;
}
else
{
return
false
;
}
}
IEntity
.
fromJson
(
dynamic
json
)
{
_code
=
json
[
"code"
];
_msg
=
json
[
"msg"
];
_data
=
json
[
"data"
];
_timestamp
=
json
[
"timestamp"
];
}
Map
<
String
,
dynamic
>
toJson
()
{
var
map
=
<
String
,
dynamic
>{};
map
[
"code"
]
=
_code
;
map
[
"msg"
]
=
_msg
;
map
[
"data"
]
=
_data
;
map
[
"timestamp"
]
=
_timestamp
;
return
map
;
}
}
netrain_flutter_app/lib/douwen/custom/http/base/IRepository.dart
0 → 100644
View file @
9c0e86b5
import
'package:flutter/foundation.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/base/IEntity.dart'
;
mixin
IRepository
{
void
getResult
<
T
>(
Future
<
IEntity
>
future
,{
@required
T
analysis
(
dynamic
data
),
@required
void
onSuccess
(
T
t
),
void
onError
(
IEntity
iEntity
),
void
onFinally
()})
async
{
IEntity
iEntity
=
await
future
;
if
(
iEntity
.
isSuccess
())
{
onSuccess
(
analysis
(
iEntity
.
data
));
}
else
{
onError
?.
call
(
iEntity
);
}
onFinally
?.
call
();
}
}
\ No newline at end of file
netrain_flutter_app/lib/douwen/custom/http/base/IService.dart
0 → 100644
View file @
9c0e86b5
import
'dart:io'
;
import
'package:dio/dio.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/base/ApiException.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/base/HttpCode.dart'
;
import
'package:netrain_flutter_app/douwen/custom/http/base/HttpUtil.dart'
;
import
'IEntity.dart'
;
mixin
IService
{
String
getServicePath
();
///获取请求对象
Dio
_getRequest
()
{
return
HttpUtil
().
getDio
(
HttpUtil
.
baseUrl
+
getServicePath
()
??
""
);
}
Future
<
IEntity
>
post
(
String
path
,
data
)
=>
_getRequest
()
.
post
(
path
,
data:
data
)
.
then
((
value
)
=>
_analysisData
(
value
))
.
catchError
((
error
)
=>
_analysisError
(
error
));
IEntity
_analysisData
(
Response
<
IEntity
>
value
)
{
IEntity
iEntity
=
value
.
data
;
return
iEntity
;
}
///这里处理公共逻辑异常
_analysisApiException
(
IEntity
iEntity
)
{
}
IEntity
_analysisError
(
var
error
)
{
IEntity
iEntity
;
if
(
error
is
DioError
)
{
dynamic
e
=
error
.
error
;
if
(
e
is
ApiException
)
{
iEntity
=
e
.
iEntity
;
_analysisApiException
(
iEntity
);
}
else
{
iEntity
=
new
IEntity
(
code:
HttpCode
.
NORMAL_ERROR
,
msg:
e
.
toString
());
}
}
return
iEntity
;
}
}
netrain_flutter_app/lib/laishanqi/netrain/DoctorHomePage.dart
View file @
9c0e86b5
...
...
@@ -101,7 +101,7 @@ class _DoctorHomePageState extends State<DoctorHomePage> {
Positioned
(
child:
Container
(
width:
68
,
height:
2
0
,
height:
1
0
,
decoration:
BoxDecoration
(
color:
Colors
.
white30
,
borderRadius:
BorderRadius
.
circular
(
10
)),
...
...
@@ -117,7 +117,8 @@ class _DoctorHomePageState extends State<DoctorHomePage> {
// ),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
// crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Text
(
"主任医师"
,
...
...
@@ -228,7 +229,6 @@ class _DoctorHomePageState extends State<DoctorHomePage> {
),
key:
Key
(
"
${list[index]}
"
),
onDismissed:
(
direction
)
{
setState
(()
{
print
(
"删除成功?
${list.remove(list[index])}
,
${list.toString()}
"
);
...
...
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