Skip to content

Instantly share code, notes, and snippets.

Created April 5, 2021 20:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yaizudamashii/0f3f53b1b473609f2cdb56d5828a37ca to your computer and use it in GitHub Desktop.
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_voice_chat_using_agora/app/home/empty_feed.dart';
import 'package:flutter_voice_chat_using_agora/app/top_level_providers.dart';
class AuthWidget extends ConsumerWidget {
const AuthWidget({
Key key,
@required this.signedInBuilder,
@required this.nonSignedInBuilder,
}) : super(key: key);
final WidgetBuilder nonSignedInBuilder;
final WidgetBuilder signedInBuilder;
Widget build(BuildContext context, ScopedReader watch) {
final authStateChanges = watch(authStateChangesProvider);
return authStateChanges.when(
data: (user) => _data(context, user),
loading: () => Scaffold(
body: Center(
child: CircularProgressIndicator(),
error: (_, __) => Scaffold(
body: EmptyFeed(
title: 'Something went wrong',
message: 'Can\'t load data right now.',
Widget _data(BuildContext context, User user) {
if (user != null) {
return signedInBuilder(context);
return nonSignedInBuilder(context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment