Guest User

Untitled

a guest
Jun 24th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1.  
  2. class HomeViewScreen extends StatefulWidget {
  3. @override
  4. _HomeViewScreenState createState() => _HomeViewScreenState();
  5. }
  6.  
  7. class _HomeViewScreenState extends State<HomeViewScreen>
  8. with TickerProviderStateMixin {
  9. AnimationController animationController;
  10. Widget tabBody = Container(
  11. color: TemaApp.background,
  12. );
  13.  
  14. List<TabIconData> tabIconsList = TabIconData.tabIconsList;
  15.  
  16. final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  17.  
  18. @override
  19. void dispose() {
  20. animationController.dispose();
  21. super.dispose();
  22. }
  23. //Disabilito il bottone di back su android
  24. bool myInterceptor(bool stopDefaultButtonEvent) {
  25. print("Bottone back disabilitato!"); // Do some stuff.
  26. return true;
  27. }
  28.  
  29. @override
  30. void initState() {
  31. BackButtonInterceptor.add(myInterceptor);
  32. tabIconsList.forEach((TabIconData tab) {
  33. tab.isSelected = false;
  34. });
  35. tabIconsList[0].isSelected = true;
  36.  
  37. animationController = AnimationController(
  38. duration: const Duration(milliseconds: 600), vsync: this);
  39. tabBody = MyDiaryScreen(animationController: animationController);
  40.  
  41. super.initState();
  42.  
  43. //Dopo aver inizializzato le view verifico che i valori siano attivi
  44. _checkParametri();
  45.  
  46. }
  47.  
  48. //Questa funzione mostra un messaggio nella snackbar
  49. void showInSnackBar(String value) {
  50. FocusScope.of(context).requestFocus(new FocusNode());
  51. _scaffoldKey.currentState?.removeCurrentSnackBar();
  52. _scaffoldKey.currentState.showSnackBar(new SnackBar(
  53. content: new Text(
  54. value,
  55. textAlign: TextAlign.center,
  56. style: TextStyle(
  57. color: Colors.white,
  58. fontSize: 16.0,
  59. fontFamily: "WorkSansSemiBold"),
  60. ),
  61. backgroundColor: Colors.blue,
  62. duration: Duration(seconds: 3),
  63. ));
  64. }
  65.  
  66. //Questa funzione viene eseguita
  67. // all'avvio dell'app per verificare che i valori siano attivi
  68. Future<void> _checkParametri() async {
  69. bool check = await Gps.isPermesso();
  70. if (!check) {
  71. showInSnackBar("Errore: GPS non attivo");
  72. }
  73. }
  74.  
  75. Future<bool> getData() async {
  76. await Future<dynamic>.delayed(const Duration(milliseconds: 200));
  77. return true;
  78. }
  79.  
  80. //Configurazione della bottombar
  81. Widget bottomBar() {
  82. return Column(
  83. children: <Widget>[
  84. const Expanded(
  85. child: SizedBox(),
  86. ),
  87. BottomBarView(
  88. tabIconsList: tabIconsList,
  89. addClick: () {
  90. super.dispose();
  91. },
  92. changeIndex: (int index) {
  93.  
  94. //Indice per il marcatempo
  95. if (index == 0) {
  96. animationController.reverse().then<dynamic>((data) {
  97. if (!mounted) {
  98. return;
  99. }
  100. setState(() {
  101. tabBody =
  102. MyDiaryScreen(animationController: animationController);
  103. });
  104. });
  105. }
  106. //Indice che indica la ricerca dei rapportini
  107. else if (index == 1) {
  108.  
  109. animationController.reverse().then<dynamic>((data) {
  110. print("Sono all'interno del tab 2");
  111. if (!mounted) {
  112. return;
  113. }
  114. setState(() {
  115.  
  116. var rapportiniView=new RapportiniScreen(
  117. animationController: animationController);
  118. tabBody = rapportiniView;
  119. });
  120. });
  121.  
  122. }
  123. //Indice per la ricerca dei cantieri
  124. else if (index == 2) {
  125. animationController.reverse().then<dynamic>((data) {
  126. if (!mounted) {
  127. return;
  128. }
  129. setState(() {
  130. tabBody =
  131. UserScreen(animationController: animationController);
  132. /* tabBody = RicercaCantieriScreen(
  133. animationController: animationController);*/
  134. });
  135. });
  136. }
  137. //l'indice selezionato รจ il terzo visualizzo la schermata utenti
  138. else if (index == 3) {
  139. animationController.reverse().then<dynamic>((data) {
  140. if (!mounted) {
  141. return;
  142. }
  143. setState(() {
  144. tabBody =
  145. UserScreen(animationController: animationController);
  146. });
  147. });
  148. }
  149. },
  150. ),
  151. ],
  152. );
  153. }
  154.  
  155. @override
  156. Widget build(BuildContext context) {
  157. return Container(
  158. color: TemaApp.background,
  159. child: Scaffold(
  160. backgroundColor: Colors.transparent,
  161. body: FutureBuilder<bool>(
  162. future: getData(),
  163. builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
  164. if (!snapshot.hasData) {
  165. return const SizedBox();
  166. } else {
  167.  
  168. return new Stack(
  169. children: <Widget>[
  170. tabBody,
  171. bottomBar(),
  172. ],
  173. );
  174. }
  175. },
  176. ),
  177. ),
  178. );
  179. }
  180. }
Add Comment
Please, Sign In to add comment