library home_view; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:stacked/stacked.dart'; import 'home_view_model.dart'; class HomeView extends StatelessWidget { @override Widget build(BuildContext context) { return ViewModelBuilder.reactive( viewModelBuilder: () => HomeViewModel( authenticationService: Provider.of(context), navigationService: Provider.of(context)), onModelReady: (viewModel) { viewModel.initialize(); viewModel.pageController = new PageController(initialPage: viewModel.tabIndex); }, builder: (context, viewModel, child) { return Scaffold( body: PageView( onPageChanged: (index) { viewModel.tabIndex = index; }, controller: viewModel.pageController, children: [ KassaTab(viewModel, 0), PrefencesTab(viewModel, 1) ], ), bottomNavigationBar: BottomNavigationBar( currentIndex: viewModel.tabIndex, type: BottomNavigationBarType.shifting, items: [ BottomNavigationBarItem( icon: Icon(Icons.add_shopping_cart, color: Color.fromARGB(255, 0, 0, 0)), title: new Text( 'Касса', style: TextStyle(color: Colors.black), )), BottomNavigationBarItem( icon: Icon(Icons.assignment, color: Color.fromARGB(255, 0, 0, 0)), title: new Text( 'Опции', style: TextStyle(color: Colors.black), )), ], onTap: (index) { viewModel.pageController.animateToPage( index, duration: const Duration(milliseconds: 300), curve: Curves.easeIn, ); }, ), ); }); } } class KassaTab extends StatelessWidget { final HomeViewModel viewModel; final int index; KassaTab(this.viewModel, this.index); @override Widget build(BuildContext context) { // TODO: implement build return Scaffold( body: Column( children: [ Text('KassaTab index:$index ${viewModel.currentUser.fullName} ') ], ), floatingActionButton: viewModel.tabIndex == 0 ? FloatingActionButton( onPressed: () {}, child: Icon( Icons.add, color: Colors.black, size: 45, ), backgroundColor: Colors.white, ) : null); } } class PrefencesTab extends StatelessWidget { final HomeViewModel viewModel; final int index; PrefencesTab(this.viewModel, this.index); @override Widget build(BuildContext context) { // TODO: implement build return Container( child: Column( children: [ Text('PrefencesTab index:$index ${viewModel.currentUser.fullName} ') ], ), ); } }