Commit f9957c52 authored by jinzhu's avatar jinzhu

update flutter

parent f5f15dff
...@@ -12,6 +12,7 @@ import 'package:flutter/material.dart'; ...@@ -12,6 +12,7 @@ import 'package:flutter/material.dart';
import 'macros/ALColors.dart'; import 'macros/ALColors.dart';
import 'macros/ALDevice.dart'; import 'macros/ALDevice.dart';
import 'netWork/DioUtil.dart'; import 'netWork/DioUtil.dart';
import 'toast/toast.dart';
class CommentSuggest extends StatelessWidget { class CommentSuggest extends StatelessWidget {
final Map params; final Map params;
...@@ -147,6 +148,7 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> { ...@@ -147,6 +148,7 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
BaseOptions options = DioUtil.getDefOptions(); BaseOptions options = DioUtil.getDefOptions();
final cookie = new Map<String, dynamic>.from(widget.nativeCookie); final cookie = new Map<String, dynamic>.from(widget.nativeCookie);
HttpConfig config = new HttpConfig(options: options, nativeCookie: cookie); HttpConfig config = new HttpConfig(options: options, nativeCookie: cookie);
DioUtil.openDebug();
DioUtil().setConfig(config); DioUtil().setConfig(config);
print('aaaaaaaa----come----config'); print('aaaaaaaa----come----config');
print(config.nativeCookie); print(config.nativeCookie);
...@@ -154,9 +156,11 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> { ...@@ -154,9 +156,11 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
print(widget.nativeCookie); print(widget.nativeCookie);
DioUtil().requestR(Method.post, "api/v1/suggestion",data: {"content": "add", "phone": "aaa"}).then((res){ DioUtil().requestR(Method.post, "api/v1/suggestion",data: {"content": "add", "phone": "aaa"}).then((res){
print('请求成功'); if (res.code == 0) {
print(res); Toast.show(context, '请求成功');
// showAlertDialog(context, '请求成功'); } else {
Toast.show(context, res.msg);
}
} }
).then((error){ ).then((error){
print(error); print(error);
...@@ -179,7 +183,7 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> { ...@@ -179,7 +183,7 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
] ]
)); ));
} }
} }
...@@ -221,13 +221,16 @@ class DioUtil { ...@@ -221,13 +221,16 @@ class DioUtil {
T _data; T _data;
T _extra; T _extra;
T _userType; T _userType;
_status = response.statusCode.toString();
if (response.statusCode == HttpStatus.ok || if (response.statusCode == HttpStatus.ok ||
response.statusCode == HttpStatus.created) { response.statusCode == HttpStatus.created) {
try { try {
if (response.data is Map) { if (response.data is Map) {
_status = (response.data[_statusKey] is int) // _status = (response.data[_statusKey] is int)
? response.data[_statusKey].toString() // ? response.data[_statusKey].toString()
: response.data[_statusKey]; // : response.data[_statusKey];
_code = (response.data[_codeKey] is String) _code = (response.data[_codeKey] is String)
? int.tryParse(response.data[_codeKey]) ? int.tryParse(response.data[_codeKey])
: response.data[_codeKey]; : response.data[_codeKey];
...@@ -236,9 +239,6 @@ class DioUtil { ...@@ -236,9 +239,6 @@ class DioUtil {
_extra = response.data[_extraKey]; _extra = response.data[_extraKey];
} else { } else {
Map<String, dynamic> _dataMap = _decodeData(response); Map<String, dynamic> _dataMap = _decodeData(response);
_status = (_dataMap[_statusKey] is int)
? _dataMap[_statusKey].toString()
: _dataMap[_statusKey];
_code = (_dataMap[_codeKey] is String) _code = (_dataMap[_codeKey] is String)
? int.tryParse(_dataMap[_codeKey]) ? int.tryParse(_dataMap[_codeKey])
: _dataMap[_codeKey]; : _dataMap[_codeKey];
...@@ -255,6 +255,9 @@ class DioUtil { ...@@ -255,6 +255,9 @@ class DioUtil {
type: DioErrorType.RESPONSE, type: DioErrorType.RESPONSE,
)); ));
} }
} else {
_code = 1;
_msg = '请求失败';
} }
return new Future.error(new DioError( return new Future.error(new DioError(
response: response, response: response,
...@@ -282,15 +285,12 @@ class DioUtil { ...@@ -282,15 +285,12 @@ class DioUtil {
T _data; T _data;
T _extra; T _extra;
T _userType; T _userType;
print('打印http response');
print(response); _status = response.statusCode.toString();
if (response.statusCode == HttpStatus.ok || if (response.statusCode == HttpStatus.ok ||
response.statusCode == HttpStatus.created) { response.statusCode == HttpStatus.created) {
try { try {
if (response.data is Map) { if (response.data is Map) {
_status = (response.data[_statusKey] is int)
? response.data[_statusKey].toString()
: response.data[_statusKey];
_code = (response.data[_codeKey] is String) _code = (response.data[_codeKey] is String)
? int.tryParse(response.data[_codeKey]) ? int.tryParse(response.data[_codeKey])
: response.data[_codeKey]; : response.data[_codeKey];
...@@ -298,9 +298,6 @@ class DioUtil { ...@@ -298,9 +298,6 @@ class DioUtil {
_data = response.data[_dataKey]; _data = response.data[_dataKey];
} else { } else {
Map<String, dynamic> _dataMap = _decodeData(response); Map<String, dynamic> _dataMap = _decodeData(response);
_status = (_dataMap[_statusKey] is int)
? _dataMap[_statusKey].toString()
: _dataMap[_statusKey];
_code = (_dataMap[_codeKey] is String) _code = (_dataMap[_codeKey] is String)
? int.tryParse(_dataMap[_codeKey]) ? int.tryParse(_dataMap[_codeKey])
: _dataMap[_codeKey]; : _dataMap[_codeKey];
...@@ -317,6 +314,9 @@ class DioUtil { ...@@ -317,6 +314,9 @@ class DioUtil {
type: DioErrorType.RESPONSE, type: DioErrorType.RESPONSE,
)); ));
} }
} else {
_code = 1;
_msg = '请求失败';
} }
return new Future.error(new DioError( return new Future.error(new DioError(
response: response, response: response,
...@@ -438,7 +438,7 @@ class DioUtil { ...@@ -438,7 +438,7 @@ class DioUtil {
options.connectTimeout = 10 * 1000; options.connectTimeout = 10 * 1000;
options.receiveTimeout = 20 * 1000; options.receiveTimeout = 20 * 1000;
options.contentType = ContentType.parse('application/x-www-form-urlencoded'); 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>(); Map<String, dynamic> headers = Map<String, dynamic>();
headers['Accept'] = 'application/json'; headers['Accept'] = 'application/json';
return options; return options;
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment