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
f9957c52
Commit
f9957c52
authored
May 20, 2019
by
jinzhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update flutter
parent
f5f15dff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
183 additions
and
20 deletions
+183
-20
comment_suggest.dart
lib/comment_suggest.dart
+9
-5
DioUtil.dart
lib/netWork/DioUtil.dart
+15
-15
toast.dart
lib/toast/toast.dart
+159
-0
No files found.
lib/comment_suggest.dart
View file @
f9957c52
...
...
@@ -12,6 +12,7 @@ import 'package:flutter/material.dart';
import
'macros/ALColors.dart'
;
import
'macros/ALDevice.dart'
;
import
'netWork/DioUtil.dart'
;
import
'toast/toast.dart'
;
class
CommentSuggest
extends
StatelessWidget
{
final
Map
params
;
...
...
@@ -147,6 +148,7 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
BaseOptions
options
=
DioUtil
.
getDefOptions
();
final
cookie
=
new
Map
<
String
,
dynamic
>.
from
(
widget
.
nativeCookie
);
HttpConfig
config
=
new
HttpConfig
(
options:
options
,
nativeCookie:
cookie
);
DioUtil
.
openDebug
();
DioUtil
().
setConfig
(
config
);
print
(
'aaaaaaaa----come----config'
);
print
(
config
.
nativeCookie
);
...
...
@@ -154,9 +156,11 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
print
(
widget
.
nativeCookie
);
DioUtil
().
requestR
(
Method
.
post
,
"api/v1/suggestion"
,
data:
{
"content"
:
"add"
,
"phone"
:
"aaa"
}).
then
((
res
){
print
(
'请求成功'
);
print
(
res
);
// showAlertDialog(context, '请求成功');
if
(
res
.
code
==
0
)
{
Toast
.
show
(
context
,
'请求成功'
);
}
else
{
Toast
.
show
(
context
,
res
.
msg
);
}
}
).
then
((
error
){
print
(
error
);
...
...
@@ -164,7 +168,7 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
}
void
showAlertDialog
(
BuildContext
context
,
String
textStr
)
{
showDialog
(
showDialog
(
context:
context
,
builder:
(
_
)
=>
new
AlertDialog
(
title:
new
Text
(
textStr
),
...
...
@@ -179,7 +183,7 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
]
));
}
}
}
lib/netWork/DioUtil.dart
View file @
f9957c52
...
...
@@ -221,13 +221,16 @@ class DioUtil {
T
_data
;
T
_extra
;
T
_userType
;
_status
=
response
.
statusCode
.
toString
();
if
(
response
.
statusCode
==
HttpStatus
.
ok
||
response
.
statusCode
==
HttpStatus
.
created
)
{
try
{
if
(
response
.
data
is
Map
)
{
_status
=
(
response
.
data
[
_statusKey
]
is
int
)
?
response
.
data
[
_statusKey
].
toString
()
:
response
.
data
[
_statusKey
];
// _status = (response.data[_statusKey] is int)
// ? response.data[_statusKey].toString()
// : response.data[_statusKey];
_code
=
(
response
.
data
[
_codeKey
]
is
String
)
?
int
.
tryParse
(
response
.
data
[
_codeKey
])
:
response
.
data
[
_codeKey
];
...
...
@@ -236,9 +239,6 @@ class DioUtil {
_extra
=
response
.
data
[
_extraKey
];
}
else
{
Map
<
String
,
dynamic
>
_dataMap
=
_decodeData
(
response
);
_status
=
(
_dataMap
[
_statusKey
]
is
int
)
?
_dataMap
[
_statusKey
].
toString
()
:
_dataMap
[
_statusKey
];
_code
=
(
_dataMap
[
_codeKey
]
is
String
)
?
int
.
tryParse
(
_dataMap
[
_codeKey
])
:
_dataMap
[
_codeKey
];
...
...
@@ -255,6 +255,9 @@ class DioUtil {
type:
DioErrorType
.
RESPONSE
,
));
}
}
else
{
_code
=
1
;
_msg
=
'请求失败'
;
}
return
new
Future
.
error
(
new
DioError
(
response:
response
,
...
...
@@ -282,15 +285,12 @@ class DioUtil {
T
_data
;
T
_extra
;
T
_userType
;
print
(
'打印http response'
);
print
(
response
);
_status
=
response
.
statusCode
.
toString
(
);
if
(
response
.
statusCode
==
HttpStatus
.
ok
||
response
.
statusCode
==
HttpStatus
.
created
)
{
try
{
if
(
response
.
data
is
Map
)
{
_status
=
(
response
.
data
[
_statusKey
]
is
int
)
?
response
.
data
[
_statusKey
].
toString
()
:
response
.
data
[
_statusKey
];
_code
=
(
response
.
data
[
_codeKey
]
is
String
)
?
int
.
tryParse
(
response
.
data
[
_codeKey
])
:
response
.
data
[
_codeKey
];
...
...
@@ -298,9 +298,6 @@ class DioUtil {
_data
=
response
.
data
[
_dataKey
];
}
else
{
Map
<
String
,
dynamic
>
_dataMap
=
_decodeData
(
response
);
_status
=
(
_dataMap
[
_statusKey
]
is
int
)
?
_dataMap
[
_statusKey
].
toString
()
:
_dataMap
[
_statusKey
];
_code
=
(
_dataMap
[
_codeKey
]
is
String
)
?
int
.
tryParse
(
_dataMap
[
_codeKey
])
:
_dataMap
[
_codeKey
];
...
...
@@ -317,6 +314,9 @@ class DioUtil {
type:
DioErrorType
.
RESPONSE
,
));
}
}
else
{
_code
=
1
;
_msg
=
'请求失败'
;
}
return
new
Future
.
error
(
new
DioError
(
response:
response
,
...
...
@@ -438,7 +438,7 @@ class DioUtil {
options
.
connectTimeout
=
10
*
1000
;
options
.
receiveTimeout
=
20
*
1000
;
options
.
contentType
=
ContentType
.
parse
(
'application/x-www-form-urlencoded'
);
options
.
baseUrl
=
'http://earth.
igengmei
.com/'
;
options
.
baseUrl
=
'http://earth.
gmapp
.com/'
;
Map
<
String
,
dynamic
>
headers
=
Map
<
String
,
dynamic
>();
headers
[
'Accept'
]
=
'application/json'
;
return
options
;
...
...
lib/toast/toast.dart
0 → 100644
View file @
f9957c52
import
'package:flutter/material.dart'
;
class
Toast
{
static
ToastView
preToast
;
static
show
(
BuildContext
context
,
String
msg
)
{
var
overlayState
=
Overlay
.
of
(
context
);
var
controllerShowAnim
=
new
AnimationController
(
vsync:
overlayState
,
duration:
Duration
(
milliseconds:
250
),
);
var
controllerShowOffset
=
new
AnimationController
(
vsync:
overlayState
,
duration:
Duration
(
milliseconds:
350
),
);
var
controllerHide
=
new
AnimationController
(
vsync:
overlayState
,
duration:
Duration
(
milliseconds:
250
),
);
var
opacityAnim1
=
new
Tween
(
begin:
0.0
,
end:
1.0
).
animate
(
controllerShowAnim
);
var
controllerCurvedShowOffset
=
new
CurvedAnimation
(
parent:
controllerShowOffset
,
curve:
_BounceOutCurve
.
_
());
var
offsetAnim
=
new
Tween
(
begin:
30.0
,
end:
0.0
).
animate
(
controllerCurvedShowOffset
);
var
opacityAnim2
=
new
Tween
(
begin:
1.0
,
end:
0.0
).
animate
(
controllerHide
);
OverlayEntry
overlayEntry
;
overlayEntry
=
new
OverlayEntry
(
builder:
(
context
)
{
return
ToastWidget
(
opacityAnim1:
opacityAnim1
,
opacityAnim2:
opacityAnim2
,
offsetAnim:
offsetAnim
,
child:
buildToastLayout
(
msg
),
);
});
var
toastView
=
ToastView
();
toastView
.
overlayEntry
=
overlayEntry
;
toastView
.
controllerShowAnim
=
controllerShowAnim
;
toastView
.
controllerShowOffset
=
controllerShowOffset
;
toastView
.
controllerHide
=
controllerHide
;
toastView
.
overlayState
=
overlayState
;
preToast
=
toastView
;
toastView
.
_show
();
}
static
LayoutBuilder
buildToastLayout
(
String
msg
)
{
return
LayoutBuilder
(
builder:
(
context
,
constraints
)
{
return
IgnorePointer
(
ignoring:
true
,
child:
Container
(
child:
Material
(
color:
Colors
.
white
.
withOpacity
(
0
),
child:
Container
(
child:
Container
(
child:
Text
(
"
${msg}
"
,
style:
TextStyle
(
color:
Colors
.
white
),
),
decoration:
BoxDecoration
(
color:
Colors
.
black
.
withOpacity
(
0.6
),
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
5
),
),
),
padding:
EdgeInsets
.
symmetric
(
vertical:
10
,
horizontal:
10
),
),
margin:
EdgeInsets
.
only
(
bottom:
constraints
.
biggest
.
height
*
0.15
,
left:
constraints
.
biggest
.
width
*
0.2
,
right:
constraints
.
biggest
.
width
*
0.2
,
),
),
),
alignment:
Alignment
.
bottomCenter
,
),
);
});
}
}
class
ToastView
{
OverlayEntry
overlayEntry
;
AnimationController
controllerShowAnim
;
AnimationController
controllerShowOffset
;
AnimationController
controllerHide
;
OverlayState
overlayState
;
bool
dismissed
=
false
;
_show
()
async
{
overlayState
.
insert
(
overlayEntry
);
controllerShowAnim
.
forward
();
controllerShowOffset
.
forward
();
await
Future
.
delayed
(
Duration
(
milliseconds:
3500
));
this
.
dismiss
();
}
dismiss
()
async
{
if
(
dismissed
)
{
return
;
}
this
.
dismissed
=
true
;
controllerHide
.
forward
();
await
Future
.
delayed
(
Duration
(
milliseconds:
250
));
overlayEntry
?.
remove
();
}
}
class
ToastWidget
extends
StatelessWidget
{
final
Widget
child
;
final
Animation
<
double
>
opacityAnim1
;
final
Animation
<
double
>
opacityAnim2
;
final
Animation
<
double
>
offsetAnim
;
ToastWidget
(
{
this
.
child
,
this
.
offsetAnim
,
this
.
opacityAnim1
,
this
.
opacityAnim2
});
@override
Widget
build
(
BuildContext
context
)
{
return
AnimatedBuilder
(
animation:
opacityAnim1
,
child:
child
,
builder:
(
context
,
child_to_build
)
{
return
Opacity
(
opacity:
opacityAnim1
.
value
,
child:
AnimatedBuilder
(
animation:
offsetAnim
,
builder:
(
context
,
_
)
{
return
Transform
.
translate
(
offset:
Offset
(
0
,
offsetAnim
.
value
),
child:
AnimatedBuilder
(
animation:
opacityAnim2
,
builder:
(
context
,
_
)
{
return
Opacity
(
opacity:
opacityAnim2
.
value
,
child:
child_to_build
,
);
},
),
);
},
),
);
},
);
}
}
class
_BounceOutCurve
extends
Curve
{
const
_BounceOutCurve
.
_
();
@override
double
transform
(
double
t
)
{
t
-=
1.0
;
return
t
*
t
*
((
2
+
1
)
*
t
+
2
)
+
1.0
;
}
}
\ 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