Skip to content

Commit

Permalink
Removed Consumer widget to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince2347X committed Apr 21, 2023
1 parent 73e1157 commit 659ebee
Showing 1 changed file with 51 additions and 55 deletions.
106 changes: 51 additions & 55 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,57 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Consumer<GoogleSignInProvider>(
builder: (BuildContext context, authProvider, Widget? child) {
return SafeArea(
child: Scaffold(
body: Stack(
children: [
AnimatedSwitcher(
duration: const Duration(
milliseconds: 400,
),
transitionBuilder: (Widget widget, Animation<double> animation) {
return SlideTransition(
position: Tween<Offset>(
begin: const Offset(0.0, 0.9),
end: Offset.zero,
).animate(animation),
child: widget,
);
},
child: authProvider.isAuthenticated
? const TodosScreen()
: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: ((context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
key: Key('loading'),
child: CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
return const Center(
key: Key('error'),
child: Text('Something went wrong.'),
);
} else if (snapshot.hasData) {
return const TodosScreen(
key: Key('todos'),
);
} else {
return const SignInScreen(
key: Key('signin'),
);
}
}),
),
),
if (authProvider.isSigningIn)
const Center(
child: CircularProgressIndicator(),
),
],
),
),
);
},
return SafeArea(
child: Scaffold(
body: Stack(
children: [
AnimatedSwitcher(
duration: const Duration(
milliseconds: 400,
),
transitionBuilder: (Widget widget, Animation<double> animation) {
return SlideTransition(
position: Tween<Offset>(
begin: const Offset(0.0, 0.9),
end: Offset.zero,
).animate(animation),
child: widget,
);
},
child: Provider.of<GoogleSignInProvider>(context, listen: false).isAuthenticated
? const TodosScreen()
: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: ((context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
key: Key('loading'),
child: CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
return const Center(
key: Key('error'),
child: Text('Something went wrong.'),
);
} else if (snapshot.hasData) {
return const TodosScreen(
key: Key('todos'),
);
} else {
return const SignInScreen(
key: Key('signin'),
);
}
}),
),
),
if (Provider.of<GoogleSignInProvider>(context, listen: false).isSigningIn)
const Center(
child: CircularProgressIndicator(),
),
],
),
),
);
}
}

0 comments on commit 659ebee

Please sign in to comment.