Created
October 3, 2019 17:55
-
-
Save adityadroid/3896b83d4c2b80cf504ab9167a7fdb68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class HomePage extends StatefulWidget { | |
| @override | |
| _HomePageState createState() => _HomePageState(); | |
| } | |
| class _HomePageState extends State<HomePage> { | |
| HomeBloc homeBloc; | |
| List<Conversation> conversations = List(); | |
| @override | |
| void initState() { | |
| homeBloc = BlocProvider.of<HomeBloc>(context); | |
| homeBloc.dispatch(FetchHomeChatsEvent()); | |
| super.initState(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return SafeArea( | |
| child: Scaffold( | |
| body: CustomScrollView(slivers: <Widget>[ | |
| SliverAppBar( | |
| expandedHeight: 180.0, | |
| pinned: true, | |
| elevation: 0, | |
| centerTitle: true, | |
| actions: <Widget>[ | |
| IconButton( | |
| icon: Icon(Icons.settings), | |
| color: Theme.of(context).accentColor, | |
| onPressed: (){ | |
| Navigator.push(context, SlideLeftRoute(page:SettingsPage())); | |
| }, | |
| ) | |
| ], | |
| flexibleSpace: FlexibleSpaceBar( | |
| centerTitle: true, | |
| title: Text("Chats", style: Theme.of(context).textTheme.title), | |
| ), | |
| ), | |
| BlocBuilder<HomeBloc, HomeState>(builder: (context, state) { | |
| if (state is FetchingHomeChatsState) { | |
| return SliverToBoxAdapter( | |
| child: SizedBox( | |
| height: (MediaQuery.of(context).size.height), | |
| child: Center(child: CircularProgressIndicator()), | |
| ), | |
| ); | |
| } else if (state is FetchedHomeChatsState) { | |
| conversations = state.conversations; | |
| } | |
| return SliverList( | |
| delegate: SliverChildBuilderDelegate( | |
| (context, index) => ChatRowWidget(conversations[index]), | |
| childCount: conversations.length), | |
| ); | |
| }) | |
| ]), | |
| floatingActionButton: GradientFab( | |
| child: Icon(Icons.contacts, color: Theme.of(context).primaryColor,), | |
| onPressed: () => Navigator.push( | |
| context, SlideLeftRoute(page: ContactListPage())), | |
| ))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment