add animation to fade in (pain)

This commit is contained in:
Zypherift 2024-08-22 21:23:20 +02:00
parent c4a17633f8
commit ed0f69d155
2 changed files with 51 additions and 17 deletions

View File

@ -13,14 +13,23 @@ class KretenLoginWidget extends StatefulWidget {
State<KretenLoginWidget> createState() => _KretenLoginWidgetState(); State<KretenLoginWidget> createState() => _KretenLoginWidgetState();
} }
class _KretenLoginWidgetState extends State<KretenLoginWidget> { class _KretenLoginWidgetState extends State<KretenLoginWidget>
with TickerProviderStateMixin {
late final WebViewController controller; late final WebViewController controller;
late AnimationController _animationController;
var loadingPercentage = 0; var loadingPercentage = 0;
var currentUrl = ''; var currentUrl = '';
bool _hasFadedIn = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_animationController = AnimationController(
vsync: this, // Use the TickerProviderStateMixin
duration: const Duration(milliseconds: 300),
);
controller = WebViewController() controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted) ..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate( ..setNavigationDelegate(NavigationDelegate(
@ -78,29 +87,54 @@ class _KretenLoginWidgetState extends State<KretenLoginWidget> {
// Nonce nonce = getNonce(nonceStr, ); // Nonce nonce = getNonce(nonceStr, );
// } // }
@override
void dispose() {
// Step 3: Dispose of the animation controller
_animationController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Trigger the fade-in animation only once when loading reaches 100%
if (loadingPercentage == 100 && !_hasFadedIn) {
_animationController.forward(); // Play the animation
_hasFadedIn =
true; // Set the flag to true, so the animation is not replayed
}
return Stack( return Stack(
children: [ children: [
// WebView that will only be visible when the loading is 100% // Webview that will be displayed only when the loading is 100%
Visibility( if (loadingPercentage == 100)
visible: loadingPercentage == 100, FadeTransition(
maintainState: true, // Keep the WebView running in the background opacity: Tween<double>(begin: 0, end: 1).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
),
),
child: WebViewWidget( child: WebViewWidget(
controller: controller, controller: controller,
), ),
), ),
// Show the CircularProgressIndicator while loading is not 100% // Show the CircularProgressIndicator while loading is not 100%
if (loadingPercentage < 100) if (loadingPercentage < 100)
Center( Center(
child: Column( child: TweenAnimationBuilder(
tween: Tween<double>(begin: 0, end: loadingPercentage / 100.0),
duration: const Duration(milliseconds: 300),
builder: (context, double value, child) {
return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
CircularProgressIndicator( CircularProgressIndicator(
value: loadingPercentage / value: value, // Smoothly animates the progress
100.0, // Shows progress as a percentage
), ),
], ],
);
},
), ),
), ),
], ],

View File

@ -242,7 +242,7 @@ class LoginScreenState extends State<LoginScreen> {
height: MediaQuery.of(context) height: MediaQuery.of(context)
.size .size
.height * .height *
0.8 + 0.9 +
MediaQuery.of(context) MediaQuery.of(context)
.viewInsets .viewInsets
.bottom, .bottom,