Commit 3a3afd56 by Rizal Hermawan

feat (ui component): add alert, appbar, avatar, badge button badge and icon badge components

parent 9d608f3e
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# #
# For more info see: https://dart.dev/go/dot-packages-deprecation # For more info see: https://dart.dev/go/dot-packages-deprecation
# #
# Generated by pub on 2021-06-03 17:24:23.151930. # Generated by pub on 2021-06-06 16:33:07.886596.
async:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/async-2.5.0/lib/ async:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/async-2.5.0/lib/
boolean_selector:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib/ boolean_selector:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib/
characters:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/ characters:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/
......
...@@ -37,4 +37,18 @@ export 'package:llswidget/src/components/image/lls_image_overlay.dart'; ...@@ -37,4 +37,18 @@ export 'package:llswidget/src/components/image/lls_image_overlay.dart';
//exports accordion //exports accordion
export 'package:llswidget/src/components/accordion/lls_accordion.dart'; export 'package:llswidget/src/components/accordion/lls_accordion.dart';
//exports alert //exports alert
export 'package:llswidget/src/components/alert/lls_alert.dart'; export 'package:llswidget/src/components/alert/lls_alert.dart';
\ No newline at end of file //exports appbar
export 'package:llswidget/src/components/appbar/lls_appbar.dart';
//exports avatar
export 'package:llswidget/src/components/avatar/lls_avatar.dart';
//exports avatar shape
export 'package:llswidget/src/components/avatar/shape/lls_avatar_shape.dart';
//exports badge
export 'package:llswidget/src/components/badge/lls_badge.dart';
//exports badge shape
export 'package:llswidget/src/components/badge/shape/lls_badge_shape.dart';
//exports button badge
export 'package:llswidget/src/components/badge/lls_button_badge.dart';
//exports icon badge
export 'package:llswidget/src/components/badge/lls_icon_badge.dart';
...@@ -4,7 +4,7 @@ import 'view/cancel.dart'; ...@@ -4,7 +4,7 @@ import 'view/cancel.dart';
import 'view/confirm.dart'; import 'view/confirm.dart';
import 'view/success.dart'; import 'view/success.dart';
import '../../../llswidget.dart'; import 'package:llswidget/llswidget.dart';
//Return false to keey dialog showing //Return false to keey dialog showing
typedef bool LLSAlertOnPress(bool isConfirm); typedef bool LLSAlertOnPress(bool isConfirm);
......
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:llswidget/llswidget.dart';
class LLSAvatar extends StatelessWidget {
const LLSAvatar(
{Key? key,
this.child,
this.backgroundColor,
this.backgroundImage,
this.foregroundColor,
this.radius,
this.minRadius,
this.maxRadius,
this.borderRadius,
this.shape = LLSAvatarShape.circle,
this.size = LLSSize.MEDIUM})
: assert(radius == null || (minRadius == null && maxRadius == null)),
super(key: key);
final Widget? child;
final Color? backgroundColor;
final Color? foregroundColor;
final ImageProvider? backgroundImage;
final double? radius;
final double? minRadius;
final double? maxRadius;
final double size;
final LLSAvatarShape shape;
final BorderRadius? borderRadius;
double get _minDiameter {
if (radius == null && minRadius == null && maxRadius == null) {
return 1.5 * size;
} else {
return 2.0 * (radius ?? minRadius ?? 0);
}
}
double get _maxDiameter {
if (radius == null && minRadius == null && maxRadius == null) {
return 1.5 * size;
} else {
return 2.0 * (radius ?? maxRadius ?? 0);
}
}
BoxShape get _avatarShape {
if (shape == LLSAvatarShape.circle) {
return BoxShape.circle;
} else if (shape == LLSAvatarShape.square) {
return BoxShape.rectangle;
} else if (shape == LLSAvatarShape.rounded) {
return BoxShape.rectangle;
} else {
return BoxShape.rectangle;
}
}
@override
Widget build(BuildContext context) {
final Color? backgroundColor = this.backgroundColor;
final Color? foregroundColor = this.foregroundColor;
assert(debugCheckHasMediaQuery(context));
final ThemeData theme = Theme.of(context);
TextStyle? textStyle = theme.primaryTextTheme.subtitle1?.copyWith(
color: foregroundColor,
);
Color? effectiveBackgroundColor = backgroundColor;
if (effectiveBackgroundColor == null && textStyle?.color != null) {
switch (ThemeData.estimateBrightnessForColor(textStyle!.color!)) {
case Brightness.dark:
effectiveBackgroundColor = theme.primaryColorLight;
break;
case Brightness.light:
effectiveBackgroundColor = theme.primaryColorDark;
break;
}
} else if (foregroundColor == null && textStyle != null) {
switch (ThemeData.estimateBrightnessForColor(backgroundColor!)) {
case Brightness.dark:
textStyle = textStyle.copyWith(color: theme.primaryColorLight);
break;
case Brightness.light:
textStyle = textStyle.copyWith(color: theme.primaryColorDark);
break;
}
}
final double minDiameter = _minDiameter;
final double maxDiameter = _maxDiameter;
return AnimatedContainer(
constraints: BoxConstraints(
minHeight: minDiameter,
minWidth: minDiameter,
maxWidth: maxDiameter,
maxHeight: maxDiameter,
),
duration: kThemeChangeDuration,
decoration: BoxDecoration(
color: effectiveBackgroundColor,
image: backgroundImage != null
? DecorationImage(
image: backgroundImage!,
fit: BoxFit.cover,
)
: null,
shape: _avatarShape,
borderRadius: shape == LLSAvatarShape.rounded && borderRadius == null
? BorderRadius.circular(10)
: borderRadius,
),
child: child == null && textStyle != null
? null
: Center(
child: MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
child: IconTheme(
data: theme.iconTheme.copyWith(color: textStyle?.color),
child: DefaultTextStyle(
style: textStyle!,
child: child!,
),
),
),
),
);
}
}
\ No newline at end of file
enum LLSAvatarShape { enum LLSAvatarShape {
circle, circle,
standard, rounded,
square, square,
} }
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:llswidget/llswidget.dart';
class LLSBadge extends StatefulWidget {
/// Create badges of all types, check out [LLSButtonBadge] for button badges and [LLSIconBadge] for icon type badges
const LLSBadge({
Key? key,
this.textStyle,
this.borderShape,
this.shape = LLSBadgeShape.standard,
this.color = LLSColors.DANGER,
this.textColor = LLSColors.WHITE,
this.size = LLSSize.SMALL,
this.border,
this.text,
this.child,
}) : super(key: key);
final BorderSide? border;
final ShapeBorder? borderShape;
final LLSBadgeShape shape;
final Color color;
final double size;
final Widget? child;
final String? text;
final TextStyle? textStyle;
final Color textColor;
@override
_LLSBadgeState createState() => _LLSBadgeState();
}
class _LLSBadgeState extends State<LLSBadge> {
late Color color;
late Color textColor;
Widget? child;
LLSBadgeShape? counterShape;
late double size;
double? height;
double? width;
double? fontSize;
@override
void initState() {
color = widget.color;
textColor = widget.textColor;
child = widget.text != null ? Text(widget.text ?? '') : widget.child;
counterShape = widget.shape;
size = widget.size;
super.initState();
}
@override
void didUpdateWidget(LLSBadge oldWidget) {
color = widget.color;
textColor = widget.textColor;
child = widget.text != null ? Text(widget.text ?? '') : widget.child;
counterShape = widget.shape;
size = widget.size;
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
final BorderSide shapeBorder = widget.border != null
? widget.border!
: BorderSide(
color: color,
width: 0,
);
ShapeBorder shape;
if (counterShape == LLSBadgeShape.pills) {
shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
side: shapeBorder,
);
} else if (counterShape == LLSBadgeShape.square) {
shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
side: shapeBorder,
);
} else if (counterShape == LLSBadgeShape.standard) {
shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
side: shapeBorder,
);
} else if (counterShape == LLSBadgeShape.circle) {
shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
side: shapeBorder,
);
} else {
shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
side: shapeBorder,
);
}
if (widget.size == LLSSize.SMALL) {
height = size * 0.56;
width = size * 0.73;
fontSize = size * 0.31;
} else if (widget.size == LLSSize.MEDIUM) {
height = size * 0.58;
width = size * 0.76;
fontSize = size * 0.34;
} else if (widget.size == LLSSize.LARGE) {
height = size * 0.6;
width = size * 0.79;
fontSize = size * 0.37;
} else {
height = size * 0.58;
width = size * 0.76;
fontSize = size * 0.34;
}
return Container(
height: height,
width: counterShape == LLSBadgeShape.circle ? height : width,
child: Material(
textStyle: TextStyle(
color: textColor,
fontSize: fontSize,
),
shape: widget.borderShape ?? shape,
color: color,
type: MaterialType.button,
child: Container(
child: Center(
widthFactor: 1,
heightFactor: 1,
child: child,
),
),
),
);
}
}
\ No newline at end of file
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:llswidget/llswidget.dart';
class LLSButtonBadge extends StatefulWidget {
const LLSButtonBadge({
Key? key,
required this.onPressed,
this.onHighlightChanged,
this.textStyle,
this.boxShadow,
this.badgeBoxShadow,
this.focusColor,
this.hoverColor,
this.highlightColor,
this.splashColor,
this.elevation = 0.0,
this.focusElevation = 4.0,
this.hoverElevation = 4.0,
this.highlightElevation = 1.0,
this.disabledElevation = 0.0,
this.padding = const EdgeInsets.symmetric(horizontal: 8),
this.constraints,
this.borderShape,
this.animationDuration = kThemeChangeDuration,
this.clipBehavior = Clip.none,
this.focusNode,
this.autofocus = false,
MaterialTapTargetSize? materialTapTargetSize,
this.type = LLSButtonType.solid,
this.shape = LLSButtonShape.standard,
this.color = LLSColors.PRIMARY,
this.textColor,
this.position = LLSPosition.end,
this.size = LLSSize.MEDIUM,
this.borderSide,
this.text,
this.blockButton,
this.fullWidthButton,
this.colorScheme,
this.enableFeedback,
this.onLongPress,
this.disabledColor,
this.disabledTextColor,
this.icon,
}) : materialTapTargetSize =
materialTapTargetSize ?? MaterialTapTargetSize.padded,
assert(focusElevation >= 0.0),
assert(hoverElevation >= 0.0),
assert(highlightElevation >= 0.0),
assert(disabledElevation >= 0.0),
super(
key: key,
);
final VoidCallback? onPressed;
final ValueChanged<bool>? onHighlightChanged;
final TextStyle? textStyle;
final BorderSide? borderSide;
final BoxShadow? boxShadow;
final Color? focusColor;
final Color? hoverColor;
final Color? highlightColor;
final Color? splashColor;
final double elevation;
final double hoverElevation;
final double focusElevation;
final double highlightElevation;
final double disabledElevation;
final EdgeInsetsGeometry padding;
final BoxConstraints? constraints;
final ShapeBorder? borderShape;
final Duration animationDuration;
bool get enabled => onPressed != null;
final MaterialTapTargetSize materialTapTargetSize;
final FocusNode? focusNode;
final bool autofocus;
final Clip clipBehavior;
final LLSButtonType type;
final LLSButtonShape shape;
final Color color;
final Color? disabledColor;
final Color? textColor;
final Color? disabledTextColor;
final double size;
final String? text;
final LLSPosition position;
final bool? blockButton;
final bool? fullWidthButton;
final bool? badgeBoxShadow;
final ColorScheme? colorScheme;
final bool? enableFeedback;
final VoidCallback? onLongPress;
final Widget? icon;
@override
_LLSButtonBadgeState createState() => _LLSButtonBadgeState();
}
class _LLSButtonBadgeState extends State<LLSButtonBadge> {
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(
minHeight: 26,
minWidth: 98,
),
child: Container(
height: widget.size,
child: LLSButton(
onPressed: widget.onPressed,
onHighlightChanged: widget.onHighlightChanged,
textStyle: widget.textStyle,
boxShadow: widget.boxShadow,
buttonBoxShadow: widget.badgeBoxShadow,
focusColor: widget.focusColor,
hoverColor: widget.hoverColor,
highlightColor: widget.highlightColor,
splashColor: widget.splashColor,
elevation: widget.elevation,
focusElevation: widget.focusElevation,
hoverElevation: widget.hoverElevation,
highlightElevation: widget.highlightElevation,
disabledElevation: widget.disabledElevation,
constraints: widget.constraints,
borderShape: widget.borderShape,
animationDuration: widget.animationDuration,
clipBehavior: widget.clipBehavior,
focusNode: widget.focusNode,
autofocus: widget.autofocus,
type: widget.type,
shape: widget.shape,
color: widget.color,
textColor: widget.textColor,
position: widget.position,
size: widget.size,
borderSide: widget.borderSide,
text: widget.text,
icon: widget.icon,
blockButton: widget.blockButton,
fullWidthButton: widget.fullWidthButton,
disabledColor: widget.disabledTextColor,
disabledTextColor: widget.disabledColor,
),
),
);
}
\ No newline at end of file
import 'package:flutter/material.dart';
class LLSIconBadge extends StatefulWidget {
const LLSIconBadge({
Key? key,
this.padding = const EdgeInsets.symmetric(horizontal: 8),
required this.child,
required this.counterChild,
this.right = 0
}) : super(key: key);
final Widget child;
final Widget counterChild;
final EdgeInsetsGeometry padding;
final double right;
@override
_LLSIconBadgeState createState() => _LLSIconBadgeState();
}
class _LLSIconBadgeState extends State<LLSIconBadge> {
@override
Widget build(BuildContext context) => Container(
padding: widget.padding,
child: Stack(
children: <Widget>[
widget.child,
Positioned(
right: widget.right,
child: widget.counterChild,
),
],
),
);
}
\ No newline at end of file
enum LLSAlertType {
basic,
rounded,
fullWidth,
}
\ No newline at end of file
name: llswidget name: llswidget
description: A Flutter UI Components package. description: A Flutter UI Components package.
version: 0.0.1 version: 0.0.2
author: Rizal Hermawan author: Rizal Hermawan
homepage: https://locatorlogic.com homepage: https://locatorlogic.com
......
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