Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions lib/src/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:math';

import 'package:flutter/material.dart';

import 'shimmer.dart';
import 'stylings.dart';

Expand All @@ -25,8 +27,7 @@ class SkeletonItem extends StatelessWidget {

class SkeletonAvatar extends StatelessWidget {
final SkeletonAvatarStyle style;
const SkeletonAvatar({Key? key, this.style = const SkeletonAvatarStyle()})
: super(key: key);
const SkeletonAvatar({Key? key, this.style = const SkeletonAvatarStyle()}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -39,24 +40,20 @@ class SkeletonAvatar extends StatelessWidget {
width: ((style.randomWidth != null && style.randomWidth!) ||
(style.randomWidth == null &&
(style.minWidth != null && style.maxWidth != null)))
? doubleInRange(
style.minWidth ??
((style.maxWidth ?? constraints.maxWidth) / 3),
? doubleInRange(style.minWidth ?? ((style.maxWidth ?? constraints.maxWidth) / 3),
style.maxWidth ?? constraints.maxWidth)
: style.width,
height: ((style.randomHeight != null && style.randomHeight!) ||
(style.randomHeight == null &&
(style.minHeight != null && style.maxHeight != null)))
? doubleInRange(
style.minHeight ??
((style.maxHeight ?? constraints.maxHeight) / 3),
style.minHeight ?? ((style.maxHeight ?? constraints.maxHeight) / 3),
style.maxHeight ?? constraints.maxHeight)
: style.height,
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
color: Theme.of(context).colorScheme.background,
shape: style.shape,
borderRadius:
style.shape != BoxShape.circle ? style.borderRadius : null,
borderRadius: style.shape != BoxShape.circle ? style.borderRadius : null,
),
);
},
Expand All @@ -68,8 +65,7 @@ class SkeletonAvatar extends StatelessWidget {

class SkeletonLine extends StatelessWidget {
final SkeletonLineStyle style;
const SkeletonLine({Key? key, this.style = const SkeletonLineStyle()})
: super(key: key);
const SkeletonLine({Key? key, this.style = const SkeletonLineStyle()}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -88,16 +84,14 @@ class SkeletonLine extends StatelessWidget {
return Container(
width: ((style.randomLength != null && style.randomLength!) ||
(style.randomLength == null &&
(style.minLength != null &&
style.maxLength != null)))
(style.minLength != null && style.maxLength != null)))
? doubleInRange(
style.minLength ??
((style.maxLength ?? constraints.maxWidth) / 3),
style.minLength ?? ((style.maxLength ?? constraints.maxWidth) / 3),
style.maxLength ?? constraints.maxWidth)
: style.width,
height: style.height,
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
color: Theme.of(context).colorScheme.background,
borderRadius: style.borderRadius,
),
);
Expand Down Expand Up @@ -251,5 +245,4 @@ class SkeletonListView extends StatelessWidget {
}
}

double doubleInRange(num start, num end) =>
Random().nextDouble() * (end - start) + start;
double doubleInRange(num start, num end) => Random().nextDouble() * (end - start) + start;