Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YaruPageIndicator: restore compatibility #672

Merged
merged 4 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/lib/pages/page_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _PageIndicatorPageState extends State<PageIndicatorPage> {
return ListView(
padding: const EdgeInsets.all(kYaruPagePadding),
children: [
YaruPageIndicator(
YaruPageIndicator.builder(
length: _length,
page: _page,
onTap: (page) => setState(() => _page = page),
Expand All @@ -34,7 +34,7 @@ class _PageIndicatorPageState extends State<PageIndicatorPage> {
),
),
const SizedBox(height: 15),
YaruPageIndicator(
YaruPageIndicator.builder(
length: _length,
page: _page,
onTap: (page) => setState(() => _page = page),
Expand Down
27 changes: 24 additions & 3 deletions lib/src/widgets/yaru_page_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,28 @@ typedef YaruPageIndicatorTextBuilder = Widget Function(
/// * [YaruCarousel], display a list of widgets in a carousel view.
class YaruPageIndicator extends StatelessWidget {
/// Create a [YaruPageIndicator].
const YaruPageIndicator({
YaruPageIndicator({
super.key,
required this.length,
required this.page,
this.onTap,
this.mouseCursor,
this.textBuilder,
this.textStyle,
double? dotSize,
double? dotSpacing,
}) : assert(page >= 0 && page <= length - 1),
itemBuilder = null {
itemSizeBuilder =
dotSize != null ? (_, __, ___) => Size.square(dotSize) : null;
layoutDelegate = dotSpacing != null
? YaruPageIndicatorSteppedDelegate(baseItemSpacing: dotSpacing)
: null;
}

/// Create a [YaruPageIndicator].
// ignore: prefer_const_constructors_in_immutables
YaruPageIndicator.builder({
super.key,
required this.length,
required this.page,
Expand Down Expand Up @@ -54,7 +75,7 @@ class YaruPageIndicator extends StatelessWidget {
/// If you want an animated items size, just return the largest bounds.
///
/// Defaults to a constant 12.0 square.
final YaruPageIndicatorItemBuilder<Size>? itemSizeBuilder;
late final YaruPageIndicatorItemBuilder<Size>? itemSizeBuilder;

/// Returns the [Widget] of a given item.
///
Expand All @@ -80,7 +101,7 @@ class YaruPageIndicator extends StatelessWidget {
/// Controls the items spacing, depending on the vertical constraints.
///
/// Defaults to [YaruPageIndicatorSteppedDelegate].
final YaruPageIndicatorLayoutDelegate? layoutDelegate;
late final YaruPageIndicatorLayoutDelegate? layoutDelegate;

@override
Widget build(BuildContext context) {
Expand Down