Created
July 10, 2020 15:39
-
-
Save stephaniefash/b15f00a699bc27101d0f7abfbf4db207 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
class MessagePage extends StatefulWidget { | |
@override | |
_MessagePageState createState() => _MessagePageState(); | |
} | |
class _MessagePageState extends State<MessagePage> { | |
bool isLoading = false; | |
List<MessageModel> messageList; | |
MessageProvider messageProvider = new MessageProvider(); | |
@override | |
void initState() { | |
_fetchData(); | |
super.initState(); | |
} | |
Future _fetchData() async { | |
setState(() => isLoading = true); | |
messageList = await messageProvider.fetchPosts(); | |
setState(() => isLoading = false); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
backgroundColor: Colors.pinkAccent, | |
title: Center(child: Text('Messages', style: TextStyle(color: Colors.black),),), | |
), | |
body: Center( | |
child: isLoading | |
? CircularProgressIndicator() | |
: ListView.builder( | |
itemCount: messageList.length, | |
itemBuilder: (BuildContext context, int index) { | |
return ListTile( | |
contentPadding: EdgeInsets.symmetric( | |
horizontal: 10.0, | |
vertical: 10.0 | |
), | |
title: Text(messageList[index].email, style: TextStyle(fontSize: 20),), | |
subtitle: Text(messageList[index].body) | |
); | |
}, | |
) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment