Created
May 4, 2020 13:03
-
-
Save TheAnimatrix/58c24add42b7432649661a9931b4a837 to your computer and use it in GitHub Desktop.
an idea..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
runApp(MainApp()); | |
} | |
class MainApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
MiniApp miniApp = MiniApp(); | |
return StreamBuilder<Object>( | |
stream: miniApp.stateStream, | |
builder: (context, snapshot) { | |
if(snapshot.connectionstate=waiting) return loader | |
if(snapshot.data!="AUTHENTICATED") | |
return miniApp.buildWidget; | |
else | |
return other; | |
} | |
); | |
} | |
} | |
//let this be the mini-app | |
class MiniApp{ | |
Widget w; | |
Stream s; | |
MiniApp(); | |
Widget get buildWidget | |
{ | |
return Builder(builder: (ctx){ | |
return MyApp(); //pass stream controller etc to widget and set s | |
},); | |
} | |
Stream get stateStream | |
{ | |
return s; | |
} | |
} | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return StreamProvider.value( | |
child: MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
fontFamily: 'PS', | |
primarySwatch: Colors.red, | |
), | |
home: Wrapper()), | |
value: AuthService().user, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment