feature: Improved banners, made banner settings easier to understand. (#71)

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
PartyDonut 2024-10-24 23:02:10 +02:00 committed by GitHub
parent 11e0e106d3
commit 476bdc130e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 916 additions and 666 deletions

View file

@ -48,7 +48,8 @@ class FladderCarousel extends StatefulWidget {
/// Creates a Material Design carousel.
const FladderCarousel({
super.key,
this.padding,
this.itemPadding,
this.padding = EdgeInsets.zero,
this.backgroundColor,
this.elevation,
this.shape,
@ -68,7 +69,9 @@ class FladderCarousel extends StatefulWidget {
/// The amount of space to surround each carousel item with.
///
/// Defaults to [EdgeInsets.all] of 4 pixels.
final EdgeInsets? padding;
final EdgeInsets? itemPadding;
final EdgeInsets padding;
/// The background color for each carousel item.
///
@ -234,7 +237,7 @@ class _CarouselViewState extends State<FladderCarousel> {
final AxisDirection axisDirection = _getDirection(context);
final ScrollPhysics physics =
widget.itemSnapping ? const CarouselScrollPhysics() : ScrollConfiguration.of(context).getScrollPhysics(context);
final EdgeInsets effectivePadding = widget.padding ?? const EdgeInsets.all(4.0);
final EdgeInsets effectivePadding = widget.itemPadding ?? const EdgeInsets.all(4.0);
final Color effectiveBackgroundColor = widget.backgroundColor ?? Theme.of(context).colorScheme.surface;
final double effectiveElevation = widget.elevation ?? 0.0;
final ShapeBorder effectiveShape =
@ -266,7 +269,10 @@ class _CarouselViewState extends State<FladderCarousel> {
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Padding(
padding: effectivePadding,
padding: effectivePadding.add(EdgeInsets.only(
left: index == 0 ? widget.padding.left : 0,
right: index == widget.children.length - 1 ? widget.padding.right : 0,
)),
child: Material(
clipBehavior: Clip.antiAlias,
color: effectiveBackgroundColor,
@ -276,29 +282,31 @@ class _CarouselViewState extends State<FladderCarousel> {
fit: StackFit.expand,
children: <Widget>[
widget.children.elementAt(index),
Material(
color: Colors.transparent,
child: InkWell(
onTap: widget.onTap != null ? () => widget.onTap!.call(index) : null,
onLongPress: widget.onLongPress != null ? () => widget.onLongPress!.call(index) : null,
onSecondaryTapDown: widget.onSecondaryTap != null
? (details) => widget.onSecondaryTap!.call((index, details))
: null,
overlayColor: widget.overlayColor ??
WidgetStateProperty.resolveWith((Set<WidgetState> states) {
if (states.contains(WidgetState.pressed)) {
return theme.colorScheme.onSurface.withOpacity(0.1);
}
if (states.contains(WidgetState.hovered)) {
return theme.colorScheme.onSurface.withOpacity(0.08);
}
if (states.contains(WidgetState.focused)) {
return theme.colorScheme.onSurface.withOpacity(0.1);
}
return null;
}),
if (widget.onTap != null || widget.onSecondaryTap != null || widget.onLongPress != null)
Material(
color: Colors.transparent,
child: InkWell(
onTap: widget.onTap != null ? () => widget.onTap!.call(index) : null,
onLongPress:
widget.onLongPress != null ? () => widget.onLongPress!.call(index) : null,
onSecondaryTapDown: widget.onSecondaryTap != null
? (details) => widget.onSecondaryTap!.call((index, details))
: null,
overlayColor: widget.overlayColor ??
WidgetStateProperty.resolveWith((Set<WidgetState> states) {
if (states.contains(WidgetState.pressed)) {
return theme.colorScheme.onSurface.withOpacity(0.1);
}
if (states.contains(WidgetState.hovered)) {
return theme.colorScheme.onSurface.withOpacity(0.08);
}
if (states.contains(WidgetState.focused)) {
return theme.colorScheme.onSurface.withOpacity(0.1);
}
return null;
}),
),
),
),
],
),
),

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:fladder/util/num_extension.dart';
import 'package:fladder/widgets/gapped_container_shape.dart';
import 'package:flutter/material.dart';
double normalize(double min, double max, double value) {
return (value - min) / (max - min);
@ -12,6 +13,8 @@ class FladderSlider extends StatefulWidget {
final double max;
final int? divisions;
final double thumbWidth;
final Color? activeTrackColor;
final Color? inactiveTrackColor;
final bool showThumb;
final Duration animation;
final Function(double value)? onChanged;
@ -25,6 +28,8 @@ class FladderSlider extends StatefulWidget {
this.divisions,
this.onChanged,
this.thumbWidth = 6.5,
this.activeTrackColor,
this.inactiveTrackColor,
this.showThumb = true,
this.animation = const Duration(milliseconds: 100),
this.onChangeStart,
@ -146,6 +151,8 @@ class FladderSliderState extends State<FladderSlider> with SingleTickerProviderS
height: height,
width: constraints.maxWidth,
child: GappedContainerShape(
activeColor: widget.activeTrackColor,
inActiveColor: widget.inactiveTrackColor,
thumbPosition: relativeValue,
),
),