vitareinforce

home_view.dart

May 11th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. import 'package:kawal_desa/constants/helper.dart';
  2. import 'package:kawal_desa/constants/route_name.dart';
  3. import 'package:kawal_desa/ui/shared/shared_style.dart';
  4. import 'package:kawal_desa/ui/widgets/list_content_widget.dart';
  5. import 'package:kawal_desa/viewmodels/home_view_model.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:kawal_desa/ui/shared/colors_helper.dart';
  9. import 'package:kawal_desa/viewmodels/questioner_view_model.dart';
  10. //import 'package:provider_architecture/provider_architecture.dart';
  11. import 'package:stacked/stacked.dart';
  12.  
  13. // import flutter services
  14. import 'package:flutter/services.dart';
  15.  
  16. class HomeView extends StatefulWidget {
  17. @override
  18. _HomeViewState createState() => _HomeViewState();
  19. }
  20.  
  21. class _HomeViewState extends State<HomeView> {
  22. int page;
  23. @override
  24. Widget build(BuildContext context) {
  25. // Lock Orientation Portait Only
  26. SystemChrome.setPreferredOrientations([
  27. DeviceOrientation.portraitUp,
  28. ]);
  29.  
  30. return ViewModelBuilder<HomeViewModel>.reactive(
  31. viewModelBuilder: () => HomeViewModel(),
  32. onModelReady: (model) => model.onModelReady(),
  33. builder: (context, model, child) => Scaffold(
  34. appBar: AppBar(
  35. title: Text('kawal desa'),
  36. actions: <Widget>[
  37. FlatButton(
  38. onPressed: () {
  39. model.goAnotherView(QuestionerViewRoute);
  40. },
  41. child: Text("AM"),
  42. ),
  43. PopupMenuButton<String>(
  44. onSelected: (item) async {
  45. print('item selected $item');
  46. if (item.contains('Profile')) {
  47. model.goAnotherView(ProfileViewRoute);
  48. } else {
  49. print('getting out');
  50. model.signOut(context);
  51. }
  52. },
  53. itemBuilder: (context) {
  54. return Helper.choices.map(
  55. (choice) {
  56. return PopupMenuItem<String>(
  57. value: choice,
  58. child: Text(choice),
  59. );
  60. },
  61. ).toList();
  62. },
  63. ),
  64. ],
  65. ),
  66. body: SafeArea(
  67. child: RefreshIndicator(
  68. onRefresh: () async {
  69. print('refresh');
  70. model.getAllReport(1);
  71. },
  72. child: Container(
  73. color: Color(0xffC1C1C1),
  74. child: Column(
  75. children: <Widget>[
  76. Expanded(
  77. child: model.absenData.length != 0
  78. ? NotificationListener<ScrollNotification>(
  79. onNotification: (ScrollNotification scrollInfo) {
  80. if (!model.isLoading &&
  81. scrollInfo.metrics.pixels ==
  82. scrollInfo.metrics.maxScrollExtent) {
  83. model.pages += 1;
  84. model.loadMoreData(model.pages);
  85. }
  86. },
  87. child: ListView.builder(
  88. padding: EdgeInsets.only(
  89. top: 8.0,
  90. bottom: 8.0,
  91. right: 4.0,
  92. left: 4.0,
  93. ),
  94. itemCount: model.absenData.length,
  95. itemBuilder: (ctx, idx) => ListContentWidget(
  96. content: '${model.absenData[idx].description}',
  97. date:
  98. '${model.formatDate(model.absenData[idx].timestamp)}',
  99. address: "",
  100. imageUrl:
  101. 'http://absensi-selfie.pptik.id/${model.absenData[idx].image}',
  102. name: '${model.absenData[idx].name}',
  103. imageLocal:
  104. '${model.absenData[idx].localImage}',
  105. ),
  106. ),
  107. )
  108. : Center(
  109. child: Text(
  110. 'None',
  111. style: profileTextStyle,
  112. ),
  113. ),
  114. ),
  115. Container(
  116. height: model.isLoading ? 50.0 : 0,
  117. color: Colors.transparent,
  118. child: Center(
  119. child: new CircularProgressIndicator(),
  120. ),
  121. ),
  122. ],
  123. ),
  124. ),
  125. ),
  126. ),
  127. floatingActionButton: Stack(
  128. children: <Widget>[
  129. Padding(padding: EdgeInsets.only(left:0),
  130. child: Align(
  131. alignment: Alignment.bottomRight,
  132. child: FloatingActionButton(
  133. onPressed: () {
  134. model.goAnotherView(AbsenViewRoute);
  135. },
  136. backgroundColor: bluePrimary,
  137. child: Icon(
  138. Icons.add,
  139. color: white,
  140. )
  141. ),
  142. ),
  143. ),
  144. Align(
  145. alignment: Alignment.bottomLeft,
  146. child: Row(
  147. children: <Widget>[
  148. Expanded(
  149. child: FloatingActionButton(
  150. onPressed: () {
  151. model.goAnotherView(HomeViewRoute);
  152. },
  153. backgroundColor: Colors.red,
  154. child: new Image.asset(
  155. "assets/sayasakitemoticon.png"
  156. ),
  157. ),
  158. ),
  159. Expanded(
  160. child: FloatingActionButton(
  161. onPressed: () {
  162. model.goAnotherView(HomeViewRoute);
  163. },
  164. backgroundColor: Colors.green,
  165. child: new Image.asset(
  166. "assets/sayasehatemoticon.png"
  167. ),
  168. ),
  169. ),
  170. Expanded(
  171. child: FloatingActionButton(
  172. onPressed: () {
  173. model.goAnotherView(HomeViewRoute);
  174. },
  175. backgroundColor: Colors.yellow,
  176. child: new Image.asset(
  177. "assets/needahugemoticon.png"
  178. ),
  179. ),
  180. ),
  181. ],
  182. )
  183. ),
  184. ]
  185. ),
  186. ),
  187. );
  188. }
  189. }
Add Comment
Please, Sign In to add comment