Skip to content

Instantly share code, notes, and snippets.

@VB10
Created October 31, 2022 11:24
Show Gist options
  • Save VB10/897533953e687aacc738a45eab84be3f to your computer and use it in GitHub Desktop.
Save VB10/897533953e687aacc738a45eab84be3f to your computer and use it in GitHub Desktop.
Widget switcher with animation
import 'package:flutter/material.dart';
import 'package:kartal/kartal.dart';
class AnimatedPageSwitch extends StatelessWidget {
const AnimatedPageSwitch(
{super.key,
required this.isPageLoaded,
required this.loaderChild,
required this.completedChild});
final bool isPageLoaded;
final Widget loaderChild;
final Widget completedChild;
@override
Widget build(BuildContext context) {
return AnimatedCrossFade(
duration: context.durationLow,
crossFadeState:
isPageLoaded ? CrossFadeState.showFirst : CrossFadeState.showSecond,
firstChild: loaderChild,
secondChild: isPageLoaded ? const SizedBox.shrink() : completedChild,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment