Browse Source

发布0.1.0版本,详细请看CHANGELO.md

Kevin 6 years ago
parent
commit
30902c488f

+ 6 - 1
CHANGELOG.md

@@ -6,4 +6,9 @@
 
 * TODO: 添加了CupertinoPopoverMenuList
 * TODO: 添加了CupertinoPopoverMenuItem
-* TODO: 修改了CupertionPopover动画,
+* TODO: 修改了CupertionPopover动画,
+
+## [0.1.0] - TODO: 改进了CupertionPopover和添加了CupertinoPopoverMenuItem
+
+* TODO: 改进了CupertionPopover箭头的位置
+* TODO: 改进了CupertinoPopoverMenuItem按下的动画,并且添加了onTap

+ 1 - 1
README.md

@@ -6,7 +6,7 @@ Usage
 Add this to your package's pubspec.yaml file:
 ``` yaml
 dependencies:
-  cool_ui: "^0.0.9"
+  cool_ui: "^0.1.0"
 ```
 
 ## CupertinoPopover

BIN
images/popover_demo.gif


+ 2 - 2
lib/cool_ui.dart

@@ -4,5 +4,5 @@ import 'package:flutter/material.dart';
 part 'utils/screen_utils.dart';
 part 'utils/widget_utils.dart';
 
-part 'popover/cupertino_popover.dart';
-part 'popover/cupertino_popover_menu_item.dart';
+part 'widgets/popover/cupertino_popover.dart';
+part 'widgets/popover/cupertino_popover_menu_item.dart';

+ 0 - 62
lib/popover/cupertino_popover_menu_item.dart

@@ -1,62 +0,0 @@
-part of cool_ui;
-
-
-class CupertinoPopoverMenuList extends StatelessWidget{
-  final List<Widget> children;
-  const CupertinoPopoverMenuList({this.children});
-
-  @override
-  Widget build(BuildContext context) {
-    return ListView.builder(
-      itemCount: children.length * 2 - 1,
-      itemBuilder: (context,int i){
-        if(i.isOdd){
-          // 在每一列之前,添加一个1像素高的分隔线widget
-          return const Divider(height: 1.0,);
-        }
-        final int index=i ~/2;
-        return children[index];
-      },
-      padding: EdgeInsets.all(0.0),
-    );
-  }
-
-}
-
-
-class CupertinoPopoverMenuItem extends StatelessWidget{
-  final Widget leading;
-  final Widget child;
-
-  const CupertinoPopoverMenuItem({this.leading,this.child});
-
-
-
-  @override
-  Widget build(BuildContext context) {
-    List<Widget> widgets = [];
-    if(leading != null){
-      widgets.add(Container(
-        padding: EdgeInsets.only(left:5.0,right: 5.0),
-        width: 35.0,
-        height: 35.0,
-        child: IconTheme(
-            data:IconThemeData(color: Color(0xff007aff),size: 20.0),
-            child: leading
-        ),
-      ));
-    }
-    widgets.add(Expanded(child: DefaultTextStyle(style: TextStyle(
-        color: Color(0xff007aff),
-        fontSize: 17.0
-    ), child: child)));
-    return Padding(
-      padding: EdgeInsets.only(top:2.5,bottom: 2.5),
-      child: Row(
-          children: widgets
-      ),
-    );
-
-  }
-
-}

+ 9 - 5
lib/popover/cupertino_popover.dart → lib/widgets/popover/cupertino_popover.dart

@@ -11,6 +11,10 @@ class CupertinoPopoverButton extends StatelessWidget{
   final Duration transitionDuration;
   const CupertinoPopoverButton({
     @required this.child,
+
+    @Deprecated(
+        '建议不要直接使用popoverBody,而是使用popoverBuild.'
+    )
     this.popoverBody,
     this.popoverBuild,
     this.popoverColor=Colors.white,
@@ -34,7 +38,6 @@ class CupertinoPopoverButton extends StatelessWidget{
         showGeneralDialog(
           context: context,
           pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
-            final ThemeData theme = Theme.of(context, shadowThemeOnly: true);
             return Builder(
                 builder: (BuildContext context) {
                   return Container();
@@ -169,16 +172,17 @@ class CupertinoPopoverState extends State<CupertinoPopover>  with TickerProvider
     double arrowTop = 0.0;
     double bodyTop = 0.0;
     double bodyLeft = 0.0;
-    if(widget.attachRect.left > widget.width / 2 &&  ScreenUtil.screenWidth - widget.attachRect.right > widget.width / 2){ //判断是否可以在中间
-      arrowLeft = widget.attachRect.left + widget.attachRect.width / 2  - _arrowWidth / 2;
+    arrowLeft = widget.attachRect.left +  widget.attachRect.width / 2 - _arrowWidth / 2;
+    if(widget.attachRect.left > widget.width / 2 &&
+        ScreenUtil.screenWidth - widget.attachRect.right > widget.width / 2){ //判断是否可以在中间
+
       bodyLeft = widget.attachRect.left +  widget.attachRect.width / 2 - widget.width / 2;
     }else if(widget.attachRect.left < widget.width / 2){ //靠左
       bodyLeft = 10.0;
-      arrowLeft = bodyLeft + widget.radius;
     }else{ //靠右
       bodyLeft = ScreenUtil.screenWidth - 10.0 - widget.width;
-      arrowLeft = ScreenUtil.screenWidth - 10.0  - _arrowWidth - 5 - widget.radius;
     }
+
     if(isArrowUp){
       arrowTop = widget.attachRect.bottom;
       bodyTop = arrowTop + _arrowHeight;

+ 104 - 0
lib/widgets/popover/cupertino_popover_menu_item.dart

@@ -0,0 +1,104 @@
+part of cool_ui;
+
+
+class CupertinoPopoverMenuList extends StatelessWidget{
+  final List<Widget> children;
+  const CupertinoPopoverMenuList({this.children});
+
+  @override
+  Widget build(BuildContext context) {
+    return ListView.builder(
+      itemCount: children.length * 2 - 1,
+      itemBuilder: (context,int i){
+        if(i.isOdd){
+          // 在每一列之前,添加一个1像素高的分隔线widget
+          return const Divider(height: 1.0,);
+        }
+        final int index=i ~/2;
+        return children[index];
+      },
+      padding: EdgeInsets.all(0.0),
+    );
+  }
+
+}
+
+
+class CupertinoPopoverMenuItem extends StatefulWidget{
+  final Widget leading;
+  final Widget child;
+  final VoidCallback onTap;
+  final bool isTapClosePopover;
+
+  const CupertinoPopoverMenuItem({
+    this.leading,
+    this.child,
+    this.onTap,
+    this.isTapClosePopover=true
+  });
+
+  @override
+  State<StatefulWidget> createState() =>CupertinoPopoverMenuItemState();
+}
+
+class CupertinoPopoverMenuItemState extends State<CupertinoPopoverMenuItem>{
+  bool isDown = false;
+
+  @override
+  Widget build(BuildContext context) {
+    List<Widget> widgets = [];
+    if(widget.leading != null){
+      widgets.add(Container(
+        padding: EdgeInsets.only(left:5.0,right: 5.0),
+        width: 35.0,
+        height: 35.0,
+        child: IconTheme(
+            data:IconThemeData(color: Color(0xff007aff),size: 20.0),
+            child: widget.leading
+        ),
+      ));
+    }
+    widgets.add(Expanded(child: DefaultTextStyle(style: TextStyle(
+        color: Color(0xff007aff),
+        fontSize: 17.0
+    ), child: widget.child)));
+    return GestureDetector(
+      onTapDown: (detail){
+        setState(() {
+          isDown = true;
+        });
+      },
+      onTapUp: (detail){
+        if(isDown){
+          setState(() {
+            isDown = false;
+          });
+          if(widget.onTap != null){
+            widget.onTap();
+          }
+          if(widget.isTapClosePopover){
+            Navigator.of(context).pop();
+          }
+        }
+      },
+      onTapCancel: (){
+        if(isDown){
+          setState(() {
+            isDown = false;
+          });
+        }
+      },
+      child: Container(
+        color:isDown?Color(0xFFd9d9d9):Colors.white,
+        child: Padding(
+          padding: EdgeInsets.only(top:2.5,bottom: 2.5),
+          child: Row(
+              children: widgets
+          ),
+        ),
+      ),
+    );
+
+  }
+
+}

+ 2 - 2
pubspec.yaml

@@ -1,6 +1,6 @@
 name: cool_ui
-description: 用flutter实现一些我认为好看的UI控件
-version: 0.0.9
+description: 用flutter实现一些我认为好看的UI控件,目前暂时只有Popover,不过有什么觉得好看的可以提Issue
+version: 0.1.0
 author: Kevin <liangkaikevin@gmail.com>
 homepage: https://github.com/Im-Kevin/cool_ui