Last active
July 15, 2020 04:28
-
-
Save RobertBrunhage/451b8d2eb0c462cf03127fd67a3f7668 to your computer and use it in GitHub Desktop.
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
1. | |
class UserAuthPageContainer extends StatelessWidget { | |
const UserAuthPageContainer({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Consumer((context, read) { | |
final authUser = read(authSateChangedProvider).data?.value; | |
if (authUser != null) { | |
return ProviderScope( | |
overrides: [ | |
listContainersProvider.overrideAs( | |
StreamProvider( | |
(ref) => listContainerServiceProvider.read(context).listContainers(authUser.email), | |
), | |
), | |
userProvider.overrideAs( | |
StreamProvider( | |
(ref) { | |
return userServiceProvider.read(context).user(uid: authUser.uid); | |
}, | |
), | |
), | |
], | |
child: HomePageContainer(), | |
); | |
} else { | |
return LandingPage(); | |
} | |
}); | |
} | |
} | |
// 2. inside desktop responsive (selecting a list from the left and showing that on the right) | |
Expanded( | |
child: ProviderScope( | |
key: ValueKey(homeController.selectedListContainerIndex), | |
overrides: [ | |
listContainerProvider.overrideAs( | |
StreamProvider( | |
(ref) => listContainerServiceProvider | |
.read(context) | |
.listContainer(listContainers[homeController.selectedListContainerIndex].id), | |
), | |
), | |
], | |
child: const SelectedList(), | |
), | |
), | |
//3. on mobile I navigate to the selected List screen so in the beginning I listen to it from firestore | |
class SelectedListPage extends StatefulWidget { | |
static Route<MaterialPageRoute> route(int index, String id) { | |
return MaterialPageRoute( | |
builder: (context) => SelectedListPage( | |
index: index, | |
listContainerId: id, | |
), | |
settings: const RouteSettings(name: "SelectedList Page")); | |
} | |
const SelectedListPage({Key key, @required this.index, @required this.listContainerId}) : super(key: key); | |
final int index; | |
final String listContainerId; | |
@override | |
_SelectedListPageState createState() => _SelectedListPageState(); | |
} | |
class _SelectedListPageState extends State<SelectedListPage> { | |
static const String _homePage = "Home Page"; | |
@override | |
void initState() { | |
if (Platform.isAndroid || Platform.isIOS) analyticsServiceProvider.read(context).logPage("Selected List Page"); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return ProviderScope( | |
overrides: [ | |
listContainerProvider.overrideAs( | |
StreamProvider( | |
(ref) => listContainerServiceProvider.read(context).listContainer(widget.listContainerId), | |
), | |
), | |
], | |
child: WillPopScope( | |
onWillPop: () async { | |
if (Platform.isAndroid || Platform.isIOS) analyticsServiceProvider.read(context).logPage(_homePage); | |
return true; | |
}, | |
child: Scaffold( | |
appBar: PreferredSize( | |
preferredSize: const Size.fromHeight(100), | |
child: SafeArea( | |
child: Container( | |
height: 100, | |
padding: const EdgeInsets.all(12), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
IconButton( | |
icon: const Icon(Icons.arrow_back_ios), | |
iconSize: 38, | |
color: Theme.of(context).textTheme.headline4.color, | |
onPressed: () { | |
if (Platform.isAndroid || Platform.isIOS) analyticsServiceProvider.read(context).logPage(_homePage); | |
Navigator.of(context).pop(); | |
}, | |
), | |
const SizedBox(width: 8), | |
Expanded( | |
child: Consumer((context, read) { | |
final listContainer = | |
read(listContainerProvider).data == null ? ListContainer.empty() : read(listContainerProvider).data.value; | |
return Text( | |
listContainer.name, | |
overflow: TextOverflow.ellipsis, | |
style: Theme.of(context).textTheme.headline5, | |
); | |
}), | |
), | |
Consumer((context, read) { | |
final authuser = read(authSateChangedProvider).data?.value; | |
final listContainer = | |
read(listContainerProvider).data == null ? ListContainer.empty() : read(listContainerProvider).data.value; | |
if (authuser?.uid == listContainer.ownerId) { | |
return ShareListButton(listContainer: listContainer); | |
} else { | |
return const SizedBox(); | |
} | |
}), | |
Consumer((context, read) { | |
final listContainer = | |
read(listContainerProvider).data == null ? ListContainer.empty() : read(listContainerProvider).data.value; | |
return SelectedListPopupMenuButton(listContainer: listContainer); | |
}), | |
], | |
), | |
], | |
), | |
), | |
), | |
), | |
body: const SelectedList(), // Here I show the SelectedList again as the example 2. | |
), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment