54 lines
1.8 KiB
Dart
54 lines
1.8 KiB
Dart
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'home_screen.dart';
|
|
import 'logged_home.dart';
|
|
|
|
final ValueNotifier<bool> forceHomeScreen = ValueNotifier<bool>(false);
|
|
|
|
class AuthGate extends StatelessWidget {
|
|
const AuthGate({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ValueListenableBuilder<bool>(
|
|
valueListenable: forceHomeScreen,
|
|
builder: (context, forcedHome, _) {
|
|
return StreamBuilder<User?>(
|
|
stream: FirebaseAuth.instance.authStateChanges(),
|
|
builder: (context, snapshot) {
|
|
final user = snapshot.data;
|
|
|
|
final Widget child;
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
child = const SizedBox.shrink();
|
|
} else if (forcedHome || user == null) {
|
|
child = const HomeScreen(key: ValueKey('home_screen'));
|
|
} else {
|
|
child = const LoggedHomeScreen(key: ValueKey('logged_home_screen'));
|
|
}
|
|
|
|
return AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 280),
|
|
reverseDuration: const Duration(milliseconds: 240),
|
|
switchInCurve: Curves.easeOutCubic,
|
|
switchOutCurve: Curves.easeInCubic,
|
|
transitionBuilder: (child, animation) {
|
|
final fade = CurvedAnimation(parent: animation, curve: Curves.easeOut);
|
|
return FadeTransition(
|
|
opacity: fade,
|
|
child: ScaleTransition(
|
|
scale: Tween<double>(begin: 0.985, end: 1.0).animate(fade),
|
|
child: child,
|
|
),
|
|
);
|
|
},
|
|
child: child,
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|