Last active
July 16, 2020 18:30
-
-
Save kauemurakami/f84e9f4fb522e886c6f0102a536dddf6 to your computer and use it in GitHub Desktop.
home page example getx_pattern
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
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; | |
import 'package:getx_pattern/app/controller/home/controller.dart'; | |
import 'package:getx_pattern/app/data/provider/api.dart'; | |
import 'package:getx_pattern/app/data/repository/posts_repository.dart'; | |
import 'package:http/http.dart' as http; | |
class HomePage extends GetView<HomeController> { | |
//repository and controller injection bindings | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('HomePage')), | |
body: Container( | |
child: GetX<MyController>( | |
initState: (state) { Get.find<MyController>().getAll() ;}, | |
builder: (_) { | |
return | |
_.postList.length < 1 | |
? Center(child: CircularProgressIndicator(),) | |
: | |
ListView.builder( | |
itemBuilder: (context, index) { | |
return ListTile( | |
title: Text(_.postList[index].title), | |
subtitle: Text(_.postList[index].body), | |
); | |
}, | |
itemCount: _.postList.length, | |
); | |
}), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment