From 9c9dc94f1b3cf996395652ddbaab81f919780940 Mon Sep 17 00:00:00 2001 From: "Serik.Uvaissov" Date: Fri, 29 May 2020 22:43:54 +0600 Subject: [PATCH] Product View Component --- lib/core/models/ProductDao.dart | 9 ++++ lib/views/home/home_view.dart | 11 ++-- lib/views/home/home_view_model.dart | 24 ++++----- lib/views/home/tabs/KassaTab.dart | 49 +++++++++++++++--- lib/widgets/components/ProductListItem.dart | 57 +++++++++++++++++++++ pubspec.lock | 7 +++ pubspec.yaml | 1 + 7 files changed, 133 insertions(+), 25 deletions(-) create mode 100644 lib/core/models/ProductDao.dart create mode 100644 lib/widgets/components/ProductListItem.dart diff --git a/lib/core/models/ProductDao.dart b/lib/core/models/ProductDao.dart new file mode 100644 index 0000000..5c96465 --- /dev/null +++ b/lib/core/models/ProductDao.dart @@ -0,0 +1,9 @@ +class ProductDao { + final String name; + final double price; + int count; + + + ProductDao( {this.name, this.price, this.count}); + +} \ No newline at end of file diff --git a/lib/views/home/home_view.dart b/lib/views/home/home_view.dart index 31e1bc1..2d97129 100644 --- a/lib/views/home/home_view.dart +++ b/lib/views/home/home_view.dart @@ -4,14 +4,15 @@ import 'package:aman_kassa_flutter/shared/app_colors.dart'; import 'package:aman_kassa_flutter/shared/shared_styles.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; import 'package:provider/provider.dart'; import 'package:stacked/stacked.dart'; +import 'package:aman_kassa_flutter/core/models/ProductDao.dart'; +import 'package:aman_kassa_flutter/widgets/components/ProductListItem.dart'; import 'home_view_model.dart'; part './tabs/KassaTab.dart'; - part './tabs/CalculatorTab.dart'; - part './tabs/AdditionalTab.dart'; class Choice { @@ -89,19 +90,19 @@ class HomeView extends StatelessWidget { items: [ BottomNavigationBarItem( backgroundColor: menuColor, - icon: Icon(Icons.add_shopping_cart, color: Colors.white), + icon: Icon(MdiIcons.cashRegister, color: Colors.white), title: new Text( 'Касса', style: TextStyle(color: Colors.white), )), BottomNavigationBarItem( - icon: Icon(Icons.cake, color: Colors.white), + icon: Icon(MdiIcons.calculator, color: Colors.white), title: new Text( 'Калькулятор', style: TextStyle(color: Colors.white), )), BottomNavigationBarItem( - icon: Icon(Icons.assignment, color: Colors.white), + icon: Icon(MdiIcons.tune, color: Colors.white), title: new Text( 'Опции', style: TextStyle(color: Colors.white), diff --git a/lib/views/home/home_view_model.dart b/lib/views/home/home_view_model.dart index daa6579..9d700df 100644 --- a/lib/views/home/home_view_model.dart +++ b/lib/views/home/home_view_model.dart @@ -12,27 +12,27 @@ class HomeViewModel extends BaseViewModel { AuthenticationService _authenticationService; final DialogService _dialogService = locator(); - User _currentUser ; - User get currentUser => _currentUser; - HomeViewModel({ @required AuthenticationService authenticationService, @required NavigatorService navigationService, - }) : - _authenticationService = authenticationService , - _navigationService = navigationService; + }) : _authenticationService = authenticationService, + _navigationService = navigationService; + + User _currentUser; + User get currentUser => _currentUser; int _tabIndex = 0; int get tabIndex => this._tabIndex; + set tabIndex(int index) { + this._tabIndex = index; + notifyListeners(); + } + PageController get pageController => this._pageController; PageController _pageController; set pageController(PageController pageController) { this._pageController = pageController; } - set tabIndex(int index) { - this._tabIndex = index; - notifyListeners(); - } void initialize() { _currentUser = _authenticationService.currentUser; @@ -40,9 +40,7 @@ class HomeViewModel extends BaseViewModel { @override void dispose() { - // TODO: implement dispose super.dispose(); _pageController.dispose(); } - -} \ No newline at end of file +} diff --git a/lib/views/home/tabs/KassaTab.dart b/lib/views/home/tabs/KassaTab.dart index 618d2f6..6d6195f 100644 --- a/lib/views/home/tabs/KassaTab.dart +++ b/lib/views/home/tabs/KassaTab.dart @@ -1,6 +1,39 @@ part of home_view; -List litems = ["1","2","3","4","1","2","3","4","1","2","3","4","1","2","3","4","1","2","3","4","1","2","3","4","1","2","3","4","1","2","3","4"]; +List litems = [ + "1", + "2", + "3", + "4", + "1", + "2", + "3", + "4", + "1", + "2", + "3", + "4", + "1", + "2", + "3", + "4", + "1", + "2", + "3", + "4", + "1", + "2", + "3", + "4", + "1", + "2", + "3", + "4", + "1", + "2", + "3", + "4" +]; class KassaTab extends StatelessWidget { final HomeViewModel viewModel; @@ -8,13 +41,16 @@ class KassaTab extends StatelessWidget { KassaTab(this.viewModel, this.index); - Widget buildBody(BuildContext ctxt, int index) { - return new Text(litems[index]); + Widget buildItem(BuildContext ctxt, int index) { + return ProductListItem( + item: new ProductDao(name: 'Наименование', count: 123, price: 2332.02), + ); } @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: fillColor, body: Padding( padding: EdgeInsets.all(4), child: Column( @@ -53,11 +89,10 @@ class KassaTab extends StatelessWidget { ), Expanded( child: Container( - child: ListView.builder - ( + child: ListView.builder( itemCount: litems.length, - itemBuilder: (BuildContext ctxt, int index) => buildBody(ctxt, index) - ), + itemBuilder: (BuildContext ctxt, int index) => + buildItem(ctxt, index)), ), ), Row( diff --git a/lib/widgets/components/ProductListItem.dart b/lib/widgets/components/ProductListItem.dart new file mode 100644 index 0000000..cc4d1b3 --- /dev/null +++ b/lib/widgets/components/ProductListItem.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:aman_kassa_flutter/shared/app_colors.dart'; +import 'package:aman_kassa_flutter/core/models/ProductDao.dart'; + +class ProductListItem extends StatelessWidget { + + ProductDao item; + + ProductListItem({ + this.item + }); + + @override + Widget build(BuildContext context) { + return Container( + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 4), + child: Column( + children: [ + Container( + child: Row( + children: [ + Expanded( + child: Container( + color: whiteColor, + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 4), + child: Text(item.name) + ), + ), + Expanded( + child: Container( + color: whiteColor, + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 4), + child: Text('${item.price?.toString()} x ${item.count?.toString()}', textAlign: TextAlign.right) + ), + ) + ], + ), + ), + Row( + children: [ + Expanded( + child: Container( + color: whiteColor, + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 4), + child: Text(item.name) + ), + ), + Expanded( + child: Container(child: Text(item.name)), + ) + ], + ) + ], + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index a7c51d0..8b3f5db 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -137,6 +137,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.6" + material_design_icons_flutter: + dependency: "direct main" + description: + name: material_design_icons_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.5345" meta: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 007d90d..8c98e42 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: http: ^0.12.1 google_fonts: ^1.1.0 flutter_boom_menu: ^1.0.2 + material_design_icons_flutter: ^4.0.5345 dev_dependencies: flutter_test: sdk: flutter