refactor: simplify CustomFloatingActionBtn and remove unnecessary width calculations

This commit is contained in:
Moustapha Kodjo Amadou 2025-11-11 15:27:12 +01:00
parent beedb6e3b9
commit a9c8320f20
3 changed files with 42 additions and 70 deletions

View file

@ -100,15 +100,6 @@ class _MangaDetailsViewState extends ConsumerState<MangaDetailsView> {
onPressed: () { onPressed: () {
chap.pushToReaderView(context); chap.pushToReaderView(context);
}, },
textWidth: measureText(
l10n.resume,
Theme.of(context).textTheme.labelLarge!,
).width,
width: calculateDynamicButtonWidth(
l10n.resume,
Theme.of(context).textTheme.labelLarge!,
50,
), // 50 Padding, else RenderFlex overflow Exception
); );
} }
return CustomFloatingActionBtn( return CustomFloatingActionBtn(
@ -122,15 +113,6 @@ class _MangaDetailsViewState extends ConsumerState<MangaDetailsView> {
.last .last
.pushToReaderView(context); .pushToReaderView(context);
}, },
textWidth: measureText(
buttonLabel,
Theme.of(context).textTheme.labelLarge!,
).width,
width: calculateDynamicButtonWidth(
buttonLabel,
Theme.of(context).textTheme.labelLarge!,
50,
), // 50 Padding, else RenderFlex overflow Exception
); );
} }
return CustomFloatingActionBtn( return CustomFloatingActionBtn(
@ -144,15 +126,6 @@ class _MangaDetailsViewState extends ConsumerState<MangaDetailsView> {
.last .last
.pushToReaderView(context); .pushToReaderView(context);
}, },
textWidth: measureText(
buttonLabel,
Theme.of(context).textTheme.labelLarge!,
).width,
width: calculateDynamicButtonWidth(
buttonLabel,
Theme.of(context).textTheme.labelLarge!,
50,
), // 50 Padding, else RenderFlex overflow Exception
); );
}, },
) )

View file

@ -5,52 +5,60 @@ class CustomFloatingActionBtn extends StatelessWidget {
final bool isExtended; final bool isExtended;
final VoidCallback onPressed; final VoidCallback onPressed;
final String label; final String label;
final double width;
final double textWidth;
const CustomFloatingActionBtn({ const CustomFloatingActionBtn({
super.key, super.key,
required this.isExtended, required this.isExtended,
required this.onPressed, required this.onPressed,
required this.label, required this.label,
required this.width,
required this.textWidth,
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AnimatedContainer( const duration = Duration(milliseconds: 250);
height: 55, const curve = Curves.easeInOut;
width: !isExtended ? 63 : width,
duration: const Duration(milliseconds: 200), return AnimatedSize(
curve: Curves.easeIn, duration: duration,
child: FloatingActionButton( curve: curve,
alignment: Alignment.centerRight,
child: FloatingActionButton.extended(
backgroundColor: context.primaryColor, backgroundColor: context.primaryColor,
foregroundColor: Colors.white,
elevation: 4,
highlightElevation: 8,
onPressed: onPressed, onPressed: onPressed,
child: Row( extendedIconLabelSpacing: 0,
mainAxisAlignment: MainAxisAlignment.center, extendedPadding: EdgeInsets.symmetric(horizontal: 16),
children: [ icon: const Icon(Icons.play_arrow_rounded, size: 24),
Row( label: AnimatedSwitcher(
children: [ duration: duration,
const Icon(Icons.play_arrow, color: Colors.white), switchInCurve: curve,
AnimatedContainer( switchOutCurve: curve,
curve: Curves.easeIn, transitionBuilder: (child, animation) {
width: !isExtended ? 0 : 5, return SizeTransition(
duration: const Duration(milliseconds: 200), sizeFactor: animation,
), axis: Axis.horizontal,
], axisAlignment: -1,
), child: FadeTransition(opacity: animation, child: child),
AnimatedContainer( );
curve: Curves.easeIn, },
width: !isExtended ? 0 : textWidth, child: isExtended
duration: const Duration(milliseconds: 200), ? Padding(
child: Text( key: const ValueKey('extended'),
label, padding: const EdgeInsets.symmetric(horizontal: 8.0),
overflow: TextOverflow.ellipsis, child: Text(
style: const TextStyle(fontSize: 14, color: Colors.white), label,
), overflow: TextOverflow.ellipsis,
), maxLines: 1,
], style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
letterSpacing: 0.5,
),
),
)
: const SizedBox.shrink(key: ValueKey('collapsed')),
), ),
), ),
); );

View file

@ -173,15 +173,6 @@ class DownloadQueueScreen extends ConsumerWidget {
onPressed: () { onPressed: () {
ref.read(processDownloadsProvider()); ref.read(processDownloadsProvider());
}, },
textWidth: measureText(
l10n.download_queue,
Theme.of(context).textTheme.labelLarge!,
).width,
width: calculateDynamicButtonWidth(
l10n.download_queue,
Theme.of(context).textTheme.labelLarge!,
50,
), // 50 Padding, else RenderFlex overflow Exception
), ),
); );
} }