Skip to content

Instantly share code, notes, and snippets.

@stephaniefash
Created July 10, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephaniefash/b15f00a699bc27101d0f7abfbf4db207 to your computer and use it in GitHub Desktop.
Save stephaniefash/b15f00a699bc27101d0f7abfbf4db207 to your computer and use it in GitHub Desktop.
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