chore: segmented_buttons rewrite

pull/456/head
Aliaksei Tratseuski 2024-01-31 06:34:15 +04:00 committed by Inex Code
parent 8684a2a48a
commit 40f4f8822f
1 changed files with 49 additions and 35 deletions

View File

@ -46,20 +46,38 @@ class SegmentedButtons extends StatelessWidget {
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,
isSelected: isSelected, isSelected: isSelected,
onPressed: onPressed, onPressed: onPressed,
children: titles.asMap().entries.map((final entry) { children: [
final index = entry.key; for (int i = 0; i < titles.length; i++)
final title = entry.value; _ButtonSegment(
return Stack( isSelected: isSelected[i],
title: titles[i],
),
],
),
);
}
class _ButtonSegment extends StatelessWidget {
const _ButtonSegment({
required this.isSelected,
required this.title,
});
final bool isSelected;
final String title;
@override
Widget build(final BuildContext context) => Stack(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
children: [ children: [
AnimatedOpacity( AnimatedOpacity(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
opacity: isSelected[index] ? 1 : 0, opacity: isSelected ? 1 : 0,
child: AnimatedScale( child: AnimatedScale(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
curve: Curves.easeInOutCubicEmphasized, curve: Curves.easeInOutCubicEmphasized,
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
scale: isSelected[index] ? 1 : 0, scale: isSelected ? 1 : 0,
child: Icon( child: Icon(
Icons.check, Icons.check,
size: 18, size: 18,
@ -68,9 +86,8 @@ class SegmentedButtons extends StatelessWidget {
), ),
), ),
AnimatedPadding( AnimatedPadding(
padding: isSelected[index] padding:
? const EdgeInsets.only(left: 24) isSelected ? const EdgeInsets.only(left: 24) : EdgeInsets.zero,
: EdgeInsets.zero,
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
curve: Curves.easeInOutCubicEmphasized, curve: Curves.easeInOutCubicEmphasized,
child: Text( child: Text(
@ -80,7 +97,4 @@ class SegmentedButtons extends StatelessWidget {
), ),
], ],
); );
}).toList(),
),
);
} }