diff --git a/lib/aku_ui.dart b/lib/aku_ui.dart index bf56950..b1857d6 100644 --- a/lib/aku_ui.dart +++ b/lib/aku_ui.dart @@ -1,7 +1,10 @@ library aku_ui; -/// A Calculator. -class Calculator { - /// Returns [value] plus 1. - int addOne(int value) => value + 1; -} +//animated widgets +export 'animated_widgets/animated.dart'; + +//common widgets +export 'common_widgets/aku_common_widgets.dart'; + +//mixins +export 'mixins/aku_mixins.dart'; diff --git a/lib/animated_widgets/animated.dart b/lib/animated_widgets/animated.dart new file mode 100644 index 0000000..2e3bcf3 --- /dev/null +++ b/lib/animated_widgets/animated.dart @@ -0,0 +1,3 @@ +export 'animated_color_icon.dart'; +export 'animated_image_revert.dart'; +export 'animated_rotate.dart'; diff --git a/lib/animated_widgets/animated_color_icon.dart b/lib/animated_widgets/animated_color_icon.dart new file mode 100644 index 0000000..135a3dc --- /dev/null +++ b/lib/animated_widgets/animated_color_icon.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; + +///动态变化图标 +/// +class AnimatedColorIcon extends ImplicitlyAnimatedWidget { + final IconData icon; + final Color color; + final double size; + + AnimatedColorIcon({ + this.icon, + this.color, + this.size, + Duration duration = const Duration(milliseconds: 300), + Curve curve = Curves.easeInOutCubic, + }) : super( + duration: duration, + curve: curve, + ); + @override + ImplicitlyAnimatedWidgetState createState() => + _AniamtedColorIconState(); +} + +class _AniamtedColorIconState + extends AnimatedWidgetBaseState { + ColorTween _colorTween; + @override + Widget build(BuildContext context) { + return Icon( + widget.icon, + color: _colorTween.evaluate(animation), + size: widget.size, + ); + } + + @override + void forEachTween(context) { + _colorTween = context( + _colorTween, + widget.color, + (dynamic value) => ColorTween(begin: value), + ); + } +} diff --git a/lib/animated_widgets/animated_image_revert.dart b/lib/animated_widgets/animated_image_revert.dart new file mode 100644 index 0000000..f7479a3 --- /dev/null +++ b/lib/animated_widgets/animated_image_revert.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; +///动态颜色混合 +class AnimatedColorRevert extends ImplicitlyAnimatedWidget { + final Widget child; + final Color color; + + AnimatedColorRevert({ + this.child, + this.color, + Duration duration = const Duration(milliseconds: 300), + Curve curve = Curves.easeInOutCubic, + }) : super( + duration: duration, + curve: curve, + ); + @override + ImplicitlyAnimatedWidgetState createState() => + _AnimatedColorRevertState(); +} + +class _AnimatedColorRevertState + extends AnimatedWidgetBaseState { + ColorTween _colorTween; + @override + Widget build(BuildContext context) { + return ColorFiltered( + colorFilter: ColorFilter.mode( + _colorTween.evaluate(animation), + BlendMode.modulate, + ), + child: widget.child, + ); + } + + @override + void forEachTween(context) { + _colorTween = context( + _colorTween, + widget.color, + (dynamic value) => ColorTween(begin: value), + ); + } +} diff --git a/lib/animated_widgets/animated_rotate.dart b/lib/animated_widgets/animated_rotate.dart new file mode 100644 index 0000000..ad31739 --- /dev/null +++ b/lib/animated_widgets/animated_rotate.dart @@ -0,0 +1,44 @@ +import 'package:flutter/material.dart'; + +///动态旋转 +class AnimatedRotate extends ImplicitlyAnimatedWidget { + final Widget child; + final Duration duration; + final Curve curve; + final double angle; + + AnimatedRotate({ + Key key, + @required this.child, + this.duration = const Duration(milliseconds: 400), + this.curve = Curves.easeInOutCubic, + @required this.angle, + }) : super( + key: key, + duration: duration, + curve: curve, + ); + @override + ImplicitlyAnimatedWidgetState createState() => + _AnimatedRoateState(); +} + +class _AnimatedRoateState extends AnimatedWidgetBaseState { + Tween _rotateTween; + @override + Widget build(BuildContext context) { + return Transform.rotate( + angle: _rotateTween.evaluate(animation), + child: widget.child, + ); + } + + @override + void forEachTween(visitor) { + _rotateTween = visitor( + _rotateTween, + widget.angle, + (dynamic value) => Tween(begin: value), + ); + } +} diff --git a/lib/common_widgets/aku_button.dart b/lib/common_widgets/aku_button.dart new file mode 100644 index 0000000..c0cccb3 --- /dev/null +++ b/lib/common_widgets/aku_button.dart @@ -0,0 +1,47 @@ +import 'package:aku_ui/common_widgets/aku_cupertino_button.dart'; +import 'package:aku_ui/common_widgets/aku_material_button.dart'; +import 'package:aku_ui/mixins/aku_mixins.dart'; +import 'package:flutter/material.dart'; + +///按钮 +class AkuButton extends StatefulWidget { + @required + final Widget child; + final double height; + final double radius; + final EdgeInsets padding; + @required + final VoidCallback onPressed; + AkuButton({ + Key key, + this.child, + this.height = 0, + this.radius = 0, + this.onPressed, + this.padding = EdgeInsets.zero, + }) : super(key: key); + + @override + _AkuButtonState createState() => _AkuButtonState(); +} + +class _AkuButtonState extends State with PlatformMixin { + @override + Widget build(BuildContext context) { + return isIOS + ? AkuCupertinoButton( + onPressed: widget.onPressed, + child: widget.child, + radius: widget.radius, + minHeight: widget.height, + padding: widget.padding, + ) + : AkuMaterialButton( + onPressed: widget.onPressed, + child: widget.child, + radius: widget.radius, + height: widget.height, + padding: widget.padding, + ); + } +} diff --git a/lib/common_widgets/aku_common_widgets.dart b/lib/common_widgets/aku_common_widgets.dart new file mode 100644 index 0000000..fc2528a --- /dev/null +++ b/lib/common_widgets/aku_common_widgets.dart @@ -0,0 +1 @@ +export 'aku_button.dart'; \ No newline at end of file diff --git a/lib/common_widgets/aku_cupertino_button.dart b/lib/common_widgets/aku_cupertino_button.dart new file mode 100644 index 0000000..27b2205 --- /dev/null +++ b/lib/common_widgets/aku_cupertino_button.dart @@ -0,0 +1,32 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class AkuCupertinoButton extends CupertinoButton { + final VoidCallback onPressed; + final Widget child; + final Color color; + final EdgeInsetsGeometry padding; + final double radius; + final double minHeight; + final Color nullColor; + + AkuCupertinoButton({ + Key key, + @required this.onPressed, + @required this.child, + this.color = Colors.transparent, + this.padding = EdgeInsets.zero, + this.radius = 0, + this.minHeight = 0, + this.nullColor, + }) : super( + key: key, + child: child, + color: color, + onPressed: onPressed, + padding: padding, + borderRadius: BorderRadius.circular(radius), + minSize: minHeight, + disabledColor: nullColor ?? color.withAlpha(170), + ); +} diff --git a/lib/common_widgets/aku_material_button.dart b/lib/common_widgets/aku_material_button.dart new file mode 100644 index 0000000..479c7ef --- /dev/null +++ b/lib/common_widgets/aku_material_button.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; + +class AkuMaterialButton extends MaterialButton { + final VoidCallback onPressed; + final double elevation; + final double disabledElevation; + final double focusElevation; + final double highlightElevation; + final double hoverElevation; + final double height; + final double minWidth; + final double radius; + final EdgeInsets padding; + + final Widget child; + AkuMaterialButton({ + Key key, + @required this.onPressed, + this.elevation = 0, + this.disabledElevation = 0, + this.focusElevation = 0, + this.highlightElevation = 0, + this.hoverElevation = 0, + this.height = 48, + this.minWidth = 0, + this.radius = 0, + this.padding = EdgeInsets.zero, + @required this.child, + }) : super( + key: key, + onPressed: onPressed, + elevation: elevation, + disabledElevation: disabledElevation, + focusElevation: focusElevation, + highlightElevation: highlightElevation, + hoverElevation: hoverElevation, + height: height, + minWidth: minWidth, + padding: padding, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(radius), + ), + child: child, + ); +} diff --git a/lib/common_widgets/aku_round_button.dart b/lib/common_widgets/aku_round_button.dart new file mode 100644 index 0000000..8110c39 --- /dev/null +++ b/lib/common_widgets/aku_round_button.dart @@ -0,0 +1,24 @@ +import 'package:aku_ui/aku_ui.dart'; +import 'package:flutter/material.dart'; + +///圆角按钮 +class AkuRoundButton extends AkuButton { + final double height; + final VoidCallback onPressed; + final Widget child; + final EdgeInsets padding; + AkuRoundButton({ + Key key, + this.height, + @required this.child, + @required this.onPressed, + this.padding = EdgeInsets.zero, + }) : super( + key: key, + height: height, + radius: height / 2, + onPressed: onPressed, + child: child, + padding: padding, + ); +} diff --git a/lib/mixins/aku_mixins.dart b/lib/mixins/aku_mixins.dart new file mode 100644 index 0000000..76c4a34 --- /dev/null +++ b/lib/mixins/aku_mixins.dart @@ -0,0 +1 @@ +export 'platform_mixin.dart'; \ No newline at end of file diff --git a/lib/mixins/platform_mixin.dart b/lib/mixins/platform_mixin.dart new file mode 100644 index 0000000..73330dd --- /dev/null +++ b/lib/mixins/platform_mixin.dart @@ -0,0 +1,6 @@ +import 'dart:io'; + +class PlatformMixin { + bool get isIOS => Platform.isIOS; + bool get isAndroid => Platform.isAndroid; +}