提交 7efcef5b authored 作者: Kevin's avatar Kevin

修复hide后pop无效的问题

上级 844b3472
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart"
}
]
}
\ No newline at end of file
## [0.1.13] - TODO:修复hide后pop无效的问题
## [0.1.8] - TODO:完善了键盘的文档
* 完善了键盘的文档
* 完善了可发送的TextInputAction的类型
......
......@@ -8,7 +8,9 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/rendering.dart';
import 'package:flustars/flustars.dart';
part 'utils/widget_util.dart';
part 'utils/screen_util.dart';
part 'icons/cool_ui_icons.dart';
......
part of cool_ui;
typedef HideCallback = Future Function();
class WeuiToast extends TransitionRoute{
OverlayEntry _toastBarrier;
final Widget message;
......@@ -138,7 +141,7 @@ Future showWeuiSuccessToast({
}
VoidCallback showWeuiLoadingToast({
HideCallback showWeuiLoadingToast({
@required BuildContext context,
@required Widget message,
Alignment alignment = const Alignment(0.0,-0.2),
......@@ -152,7 +155,7 @@ VoidCallback showWeuiLoadingToast({
transitionBuilder:transitionBuilder);
}
VoidCallback showWeuiToast({
HideCallback showWeuiToast({
@required BuildContext context,
@required Widget message,
@required Widget icon,
......@@ -170,10 +173,9 @@ VoidCallback showWeuiToast({
}),
icon: icon,
transitionBuilder:transitionBuilder));
return (){
result.future.then((hide){
hide();
});
return () async{
var hide = await result.future;
hide();
};
}
......
part of cool_ui;
/**
* @Author: thl
* @GitHub: https://github.com/Sky24n
* @JianShu: https://www.jianshu.com/u/cbf2ad25d33a
* @Email: 863764940@qq.com
* @Description: Screen Util.
* @Date: 2018/9/8
*/
///默认设计稿尺寸(单位 dp or pt)
double _designW = 360.0;
double _designH = 640.0;
double _designD = 3.0;
/**
* 配置设计稿尺寸(单位 dp or pt)
* w 宽
* h 高
* density 像素密度
*/
void setDesignWHD(double w, double h, {double density: 3.0}) {
_designW = w;
_designH = h;
_designD = density;
}
/// Screen Util.
class _ScreenUtil {
double _screenWidth = 0.0;
double _screenHeight = 0.0;
double _screenDensity = 0.0;
double _statusBarHeight = 0.0;
double _bottomBarHeight = 0.0;
double _appBarHeight = 0.0;
double _textScaleFactor = 0.0;
MediaQueryData _mediaQueryData;
static final _ScreenUtil _singleton = _ScreenUtil();
static _ScreenUtil getInstance() {
_singleton._init();
return _singleton;
}
_init() {
MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
if (_mediaQueryData != mediaQuery) {
_mediaQueryData = mediaQuery;
_screenWidth = mediaQuery.size.width;
_screenHeight = mediaQuery.size.height;
_screenDensity = mediaQuery.devicePixelRatio;
_statusBarHeight = mediaQuery.padding.top;
_bottomBarHeight = mediaQuery.padding.bottom;
_textScaleFactor = mediaQuery.textScaleFactor;
_appBarHeight = kToolbarHeight;
}
}
/// screen width
/// 屏幕 宽
double get screenWidth => _screenWidth;
/// screen height
/// 屏幕 高
double get screenHeight => _screenHeight;
/// appBar height
/// appBar 高
double get appBarHeight => _appBarHeight;
/// screen density
/// 屏幕 像素密度
double get screenDensity => _screenDensity;
/// status bar Height
/// 状态栏高度
double get statusBarHeight => _statusBarHeight;
/// bottom bar Height
double get bottomBarHeight => _bottomBarHeight;
/// media Query Data
MediaQueryData get mediaQueryData => _mediaQueryData;
/// screen width
/// 当前屏幕 宽
static double getScreenW(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
return mediaQuery.size.width;
}
/// screen height
/// 当前屏幕 高
static double getScreenH(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
return mediaQuery.size.width;
}
/// screen density
/// 当前屏幕 像素密度
static double getScreenDensity(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
return mediaQuery.devicePixelRatio;
}
/// status bar Height
/// 当前状态栏高度
static double getStatusBarH(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
return mediaQuery.padding.top;
}
/// status bar Height
/// 当前BottomBar高度
static double getBottomBarH(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
return mediaQuery.padding.bottom;
}
/// 当前MediaQueryData
static MediaQueryData getMediaQueryData(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
return mediaQuery;
}
/// 返回根据屏幕宽适配后尺寸(单位 dp or pt)
/// size 单位 dp or pt
static double getScaleW(BuildContext context, double size) {
if (context == null || getScreenW(context) == 0.0) return size;
return size * getScreenW(context) / _designW;
}
/// 返回根据屏幕高适配后尺寸 (单位 dp or pt)
/// size 单位 dp or pt
static double getScaleH(BuildContext context, double size) {
if (context == null || getScreenH(context) == 0.0) return size;
return size * getScreenH(context) / _designH;
}
/// 返回根据屏幕宽适配后字体尺寸
/// fontSize 字体尺寸
/// sySystem 是否跟随系统字体大小设置,默认 true。
static double getScaleSp(BuildContext context, double fontSize,
{bool sySystem: true}) {
if (context == null || getScreenW(context) == 0.0) return fontSize;
return (sySystem ? MediaQuery
.of(context)
.textScaleFactor : 1.0) * fontSize * getScreenW(context) / _designW;
}
/// Orientation
/// 设备方向(portrait, landscape)
static Orientation getOrientation(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
return mediaQuery.orientation;
}
/// 返回根据屏幕宽适配后尺寸(单位 dp or pt)
/// size 单位 dp or pt
double getWidth(double size) {
return _screenWidth == 0.0 ? size : (size * _screenWidth / _designW);
}
/// 返回根据屏幕高适配后尺寸 (单位 dp or pt)
/// size 单位 dp or pt
double getHeight(double size) {
return _screenHeight == 0.0 ? size : (size * _screenHeight / _designH);
}
/// 返回根据屏幕宽适配后尺寸(单位 dp or pt)
/// sizePx 单位px
double getWidthPx(double sizePx) {
return _screenWidth == 0.0 ? (sizePx / _designD) :
(sizePx * _screenWidth / (_designW * _designD));
}
/// 返回根据屏幕高适配后尺寸(单位 dp or pt)
/// sizePx 单位px
double getHeightPx(double sizePx) {
return _screenHeight == 0.0 ? (sizePx / _designD) :
(sizePx * _screenHeight / (_designH * _designD));
}
/// 返回根据屏幕宽适配后字体尺寸
/// fontSize 字体尺寸
/// sySystem 是否跟随系统字体大小设置,默认 true。
double getSp(double fontSize, {bool sySystem: true}) {
if (_screenWidth == 0.0) return fontSize;
return (sySystem ? _textScaleFactor : 1.0) *
fontSize *
_screenWidth /
_designW;
}
}
part of cool_ui;
/**
* @Author: thl
* @GitHub: https://github.com/Sky24n
* @JianShu: https://www.jianshu.com/u/cbf2ad25d33a
* @Email: 863764940@qq.com
* @Description: Widget Util.
* @Date: 2018/9/10
*/
/// Widget Util.
class _WidgetUtil {
bool _hasMeasured = false;
double _width;
double _height;
/// Widget rendering listener.
/// Widget渲染监听.
/// context: Widget context.
/// isOnce: true,Continuous monitoring false,Listen only once.
/// onCallBack: Widget Rect CallBack.
void asyncPrepare(
BuildContext context, bool isOnce, ValueChanged<Rect> onCallBack) {
if (_hasMeasured) return;
WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) {
RenderBox box = context.findRenderObject();
if (box != null && box.semanticBounds != null) {
if (isOnce) _hasMeasured = true;
double width = box.semanticBounds.width;
double height = box.semanticBounds.height;
if (_width != width || _height != height) {
_width = width;
_height = height;
if (onCallBack != null) onCallBack(box.semanticBounds);
}
}
});
}
/// Widget渲染监听.
void asyncPrepares(bool isOnce, ValueChanged<Rect> onCallBack) {
if (_hasMeasured) return;
WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) {
if (isOnce) _hasMeasured = true;
if (onCallBack != null) onCallBack(null);
});
}
///get Widget Bounds (width, height, left, top, right, bottom and so on).Widgets must be rendered completely.
///获取widget Rect
static Rect getWidgetBounds(BuildContext context) {
RenderBox box = context.findRenderObject();
return (box != null && box.semanticBounds != null)
? box.semanticBounds
: Rect.zero;
}
///Get the coordinates of the widget on the screen.Widgets must be rendered completely.
///获取widget在屏幕上的坐标,widget必须渲染完成
static Offset getWidgetLocalToGlobal(BuildContext context) {
RenderBox box = context.findRenderObject();
return box == null ? Offset.zero : box.localToGlobal(Offset.zero);
}
}
\ No newline at end of file
......@@ -39,8 +39,8 @@ class CupertinoPopoverButton extends StatelessWidget{
if(onTap != null && onTap()){
return;
}
var offset = WidgetUtil.getWidgetLocalToGlobal(context);
var bounds = WidgetUtil.getWidgetBounds(context);
var offset = _WidgetUtil.getWidgetLocalToGlobal(context);
var bounds = _WidgetUtil.getWidgetBounds(context);
var body;
showGeneralDialog(
context: context,
......@@ -232,15 +232,15 @@ class _CupertionPopoverPositionRenderObject extends RenderShiftedBox{
Offset calcOffset(Size size){
double bodyLeft = 0.0;
var isArrowUp = ScreenUtil.getInstance().screenHeight > attachRect.bottom + size.height + CupertinoPopoverState._arrowHeight;
var isArrowUp = _ScreenUtil.getInstance().screenHeight > attachRect.bottom + size.height + CupertinoPopoverState._arrowHeight;
if(attachRect.left > size.width / 2 &&
ScreenUtil.getInstance().screenWidth - attachRect.right > size.width / 2){ //判断是否可以在中间
_ScreenUtil.getInstance().screenWidth - attachRect.right > size.width / 2){ //判断是否可以在中间
bodyLeft = attachRect.left + attachRect.width / 2 - size.width / 2;
}else if(attachRect.left < size.width / 2){ //靠左
bodyLeft = 10.0;
}else{ //靠右
bodyLeft = ScreenUtil.getInstance().screenWidth - 10.0 - size.width;
bodyLeft = _ScreenUtil.getInstance().screenWidth - 10.0 - size.width;
}
if(isArrowUp){
......@@ -342,7 +342,7 @@ class _CupertionPopoverContextRenderObject extends RenderShiftedBox{
child.layout(childConstraints, parentUsesSize: true);
size = Size(child.size.width,child.size.height + CupertinoPopoverState._arrowHeight);
final BoxParentData childParentData = child.parentData;
var isArrowUp = ScreenUtil.getInstance().screenHeight > attachRect.bottom + size.height + CupertinoPopoverState._arrowHeight;
var isArrowUp = _ScreenUtil.getInstance().screenHeight > attachRect.bottom + size.height + CupertinoPopoverState._arrowHeight;
if(isArrowUp)
{
childParentData.offset = Offset(0.0, CupertinoPopoverState._arrowHeight);
......@@ -354,7 +354,7 @@ class _CupertionPopoverContextRenderObject extends RenderShiftedBox{
// TODO: implement paint
Matrix4 transform = Matrix4.identity();
//
var isArrowUp = ScreenUtil.getInstance().screenHeight > attachRect.bottom + size.height + CupertinoPopoverState._arrowHeight;
var isArrowUp = _ScreenUtil.getInstance().screenHeight > attachRect.bottom + size.height + CupertinoPopoverState._arrowHeight;
var arrowLeft =attachRect.left + attachRect.width / 2 - CupertinoPopoverState._arrowWidth / 2 - offset.dx;
var translation = Offset(arrowLeft + CupertinoPopoverState._arrowWidth / 2,isArrowUp?0.0:size.height);
......
......@@ -29,27 +29,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.11"
cookie_jar:
dependency: transitive
description:
name: cookie_jar
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.7"
dio:
dependency: transitive
description:
name: dio
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.12"
flustars:
dependency: "direct main"
description:
name: flustars
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.7"
flutter:
dependency: "direct main"
description: flutter
......@@ -88,13 +67,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
shared_preferences:
dependency: transitive
description:
name: shared_preferences
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.3"
sky_engine:
dependency: transitive
description: flutter
......@@ -128,13 +100,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
synchronized:
dependency: transitive
description:
name: synchronized
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.5.3"
term_glyph:
dependency: transitive
description:
......@@ -165,4 +130,3 @@ packages:
version: "2.0.8"
sdks:
dart: ">=2.0.0 <3.0.0"
flutter: ">=0.1.4 <2.0.0"
name: cool_ui
description: Some practical Widget for flutter,Popover,Weui,Custom Keyboard
version: 0.1.12
version: 0.1.13
author: Kevin <liangkaikevin@gmail.com>
homepage: https://github.com/Im-Kevin/cool_ui
......@@ -11,8 +11,6 @@ dependencies:
flutter:
sdk: flutter
flustars: ^0.1.7
dev_dependencies:
flutter_test:
sdk: flutter
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论