From d916f638fbbbee8dba3e215df747d7c72cddaabc Mon Sep 17 00:00:00 2001 From: "Serik.Uvaissov" Date: Tue, 9 Jun 2020 11:13:50 +0600 Subject: [PATCH] UI done --- lib/core/entity/Category.dart | 6 + lib/core/entity/Goods.dart | 9 ++ lib/core/entity/Service.dart | 6 + lib/core/providers.dart | 37 ----- lib/core/services/DataService.dart | 6 +- lib/main.dart | 2 - lib/redux/actions/main_actions.dart | 54 ++++--- lib/shared/shared_styles.dart | 4 +- lib/views/home/home_view.dart | 10 ++ lib/views/home/home_view_model.dart | 88 ------------ lib/views/home/tabs/AdditionalTab.dart | 37 ++++- lib/views/home/tabs/CalculatorTab.dart | 1 - .../tabs/kassaView/ProductAddBottomSheet.dart | 133 +++++++++++++++--- .../calculator/calculator-button.dart | 31 +++- .../calculator/calculator-buttons.dart | 7 +- .../components/calculator/calculator.dart | 4 +- lib/widgets/fields/busy_button.dart | 14 +- lib/widgets/loader/Dialogs.dart | 26 ++++ 18 files changed, 289 insertions(+), 186 deletions(-) delete mode 100644 lib/core/providers.dart delete mode 100644 lib/views/home/home_view_model.dart create mode 100644 lib/widgets/loader/Dialogs.dart diff --git a/lib/core/entity/Category.dart b/lib/core/entity/Category.dart index edecff4..5f08460 100644 --- a/lib/core/entity/Category.dart +++ b/lib/core/entity/Category.dart @@ -29,5 +29,11 @@ class Category { name = map[Category_columnName]; } + Category.fromJson(Map map) { + id = map[Category_columnId]; + parentIn = map[Category_columnParentIn]; + name = map[Category_columnName]; + } + } diff --git a/lib/core/entity/Goods.dart b/lib/core/entity/Goods.dart index ddca0fb..6a484a5 100644 --- a/lib/core/entity/Goods.dart +++ b/lib/core/entity/Goods.dart @@ -41,5 +41,14 @@ class Good { ean = map[Goog_columnEan]; } + Good.fromJson(Map map) { + id = map[Goog_columnId]; + articul = map[Goog_columnArticul]; + name = map[Goog_columnName]; + price = double.parse(map[Goog_columnPrice]); + categoryId = map[Goog_columnCategoryId]; + ean = map[Goog_columnEan]; + } + } diff --git a/lib/core/entity/Service.dart b/lib/core/entity/Service.dart index 254c902..45ea1b5 100644 --- a/lib/core/entity/Service.dart +++ b/lib/core/entity/Service.dart @@ -35,5 +35,11 @@ class Service { price = map[Service_columnPrice]?.toDouble(); } + Service.fromJson(Map map) { + id = map[Service_columnId]; + articul = map[Service_columnArticul]; + name = map[Service_columnName]; + price = map[Service_columnPrice]?.toDouble(); } + } diff --git a/lib/core/providers.dart b/lib/core/providers.dart deleted file mode 100644 index 3afa3ff..0000000 --- a/lib/core/providers.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:aman_kassa_flutter/core/services/DataService.dart'; -import 'package:aman_kassa_flutter/core/services/DbService.dart'; -import 'package:provider/single_child_widget.dart'; - -import '../core/locator.dart'; -import '../core/services/navigator_service.dart'; -import 'package:provider/provider.dart'; - -import 'services/ApiService.dart'; -import 'services/authentication_service.dart'; - -class ProviderInjector { - static List providers = [ - ..._independentServices, - ..._dependentServices, - ..._consumableServices, - ]; - - static List _independentServices = [ -// Provider.value(value: locator()), -// Provider.value(value: locator()), -// Provider.value(value: locator()), - ]; - - static List _dependentServices = [ -// ProxyProvider( -// update: (context, api, authenticationService) => -// AuthenticationService(api: api), -// ), -// ProxyProvider2< ApiService ,DbService, DataService>( -// update: (context,api , db, authenticationService) => -// DataService(api: api, db: db), -// ) - ]; - - static List _consumableServices = []; -} diff --git a/lib/core/services/DataService.dart b/lib/core/services/DataService.dart index 25bd607..95f7509 100644 --- a/lib/core/services/DataService.dart +++ b/lib/core/services/DataService.dart @@ -36,21 +36,21 @@ class DataService extends BaseService { log.i('All tables cleaned'); for (var key in goods.body.keys) { print(goods.body[key]); - Good row = Good.fromMap(goods.body[key]); + Good row = Good.fromJson(goods.body[key]); _db.insert(Goog_tableName,row.toMap()); } log.i('Inserted ${goods.body.length} to table $Goog_tableName'); for (var el in categories.body) { print(el); - Category row = Category.fromMap(el); + Category row = Category.fromJson(el); _db.insert(Category_tableName,row.toMap()); } log.i('Inserted ${categories.body.length} to table $Category_tableName'); for (var key in services.body.keys) { print(services.body[key]); - Service row = Service.fromMap(services.body[key]); + Service row = Service.fromJson(services.body[key]); _db.insert(Service_tableName,row.toMap()); } log.i('Inserted ${services.body.length} to table $Service_tableName'); diff --git a/lib/main.dart b/lib/main.dart index f7d1394..76b7604 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,10 +6,8 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; //service & tools -import 'package:redux/redux.dart'; import 'package:aman_kassa_flutter/redux/store.dart'; import 'core/locator.dart'; -import 'core/providers.dart'; import 'core/router.dart'; import 'core/services/navigator_service.dart'; import 'core/services/dialog_service.dart'; diff --git a/lib/redux/actions/main_actions.dart b/lib/redux/actions/main_actions.dart index f2dfbbb..991219d 100644 --- a/lib/redux/actions/main_actions.dart +++ b/lib/redux/actions/main_actions.dart @@ -26,24 +26,39 @@ final ApiService _api = locator(); final DataService _dataService = locator(); final NavigatorService _navigation = locator(); - Future backBottomElement(Store store) async { List prevCategories = store.state.mainState.prevCategories; DictDao last = prevCategories.removeLast(); - if(last!=null) { - store.dispatch(SetMainStateAction(MainState(prevCategories: prevCategories))); + if (last != null) { + store.dispatch( + SetMainStateAction(MainState(prevCategories: prevCategories))); store.dispatch(selectBottomElement(last.id)); } } +ThunkAction addCustomProductToKassaItems(String name, int count, double price) { + return (Store store) async { + List items = store.state.mainState.kassaItems; + items.add(new ProductDao(name: name, count: count, price: price)); + store.dispatch(SetMainStateAction(MainState(kassaItems: items))); + }; +} + ThunkAction addProductToKassaItems(Good good) { return (Store store) async { List items = store.state.mainState.kassaItems; - items.add(new ProductDao(name: good.name, good: good, count: 1, price: good.price)); - store.dispatch(SetMainStateAction(MainState(kassaItems: items))); + int index = items.indexWhere((element) => element.good?.id == good.id); + if (index > -1) { + store.dispatch(counterProductFromKassaItems(index, 1)); + } else { + items.add(new ProductDao( + name: good.name, good: good, count: 1, price: good.price)); + store.dispatch(SetMainStateAction(MainState(kassaItems: items))); + } }; } + ThunkAction removeProductFromKassaItems(int index) { return (Store store) async { List items = List.from(store.state.mainState.kassaItems); @@ -51,13 +66,15 @@ ThunkAction removeProductFromKassaItems(int index) { store.dispatch(SetMainStateAction(MainState(kassaItems: items))); }; } + ThunkAction counterProductFromKassaItems(int index, int counter) { return (Store store) async { List items = store.state.mainState.kassaItems; - if(items.elementAt(index).count == 1 && counter < 0) {//if count to zero need delete element + if (items.elementAt(index).count == 1 && counter < 0) { + //if count to zero need delete element store.dispatch(removeProductFromKassaItems(index)); } else { - items.elementAt(index).count+=counter; + items.elementAt(index).count += counter; store.dispatch(SetMainStateAction(MainState(kassaItems: items))); } }; @@ -68,28 +85,25 @@ ThunkAction selectBottomElement(int parentId) { store.dispatch(SetMainStateAction(MainState(bottomSheetLoading: true))); try { List prevCategories = store.state.mainState.prevCategories; - if(parentId == 0) { + if (parentId == 0) { prevCategories = []; } store.state.mainState.bottomSheetElements.forEach((element) { - if(element is Category && element.id == parentId){ + if (element is Category && element.id == parentId) { prevCategories.add(DictDao(id: element.parentIn, name: element.name)); } }); - List categories = await _dataService.getCategoriesByParentId(parentId: parentId); - List goods = await _dataService.getGoodsByCategoryId(categoryId: parentId); + List categories = + await _dataService.getCategoriesByParentId(parentId: parentId); + List goods = + await _dataService.getGoodsByCategoryId(categoryId: parentId); List _bottomSheetElements = []; _bottomSheetElements.addAll(categories); _bottomSheetElements.addAll(goods); - store.dispatch( - SetMainStateAction( - MainState( - bottomSheetLoading: false, - bottomSheetElements: _bottomSheetElements, - prevCategories: prevCategories - ) - ) - ); + store.dispatch(SetMainStateAction(MainState( + bottomSheetLoading: false, + bottomSheetElements: _bottomSheetElements, + prevCategories: prevCategories))); } catch (e) { print(e); store.dispatch(SetMainStateAction(MainState(bottomSheetLoading: false))); diff --git a/lib/shared/shared_styles.dart b/lib/shared/shared_styles.dart index d91a225..29d87a6 100644 --- a/lib/shared/shared_styles.dart +++ b/lib/shared/shared_styles.dart @@ -21,8 +21,8 @@ const EdgeInsets largeFieldPadding = // Text Variables const TextStyle productTextStyle = const TextStyle(fontWeight: FontWeight.w400, color: Colors.black, fontSize: 15); -const TextStyle buttonTitleTextStyle = const TextStyle(fontWeight: FontWeight.w400, color: whiteColor, fontSize: 15); -const TextStyle buttonBigTitleTextStyle = const TextStyle(fontWeight: FontWeight.w400, color: whiteColor, fontSize: 22, ); +const TextStyle buttonTitleTextStyle = const TextStyle(fontWeight: FontWeight.w700, color: whiteColor, fontSize: 15); +const TextStyle buttonBigTitleTextStyle = const TextStyle(fontWeight: FontWeight.w700, color: whiteColor, fontSize: 22, ); const TextStyle stepTitleTextStyle = const TextStyle(fontWeight: FontWeight.w700, color: textColor, fontSize: 15); diff --git a/lib/views/home/home_view.dart b/lib/views/home/home_view.dart index 1732107..6d94f26 100644 --- a/lib/views/home/home_view.dart +++ b/lib/views/home/home_view.dart @@ -3,6 +3,7 @@ import 'package:aman_kassa_flutter/core/models/Choice.dart'; import 'package:aman_kassa_flutter/core/services/DataService.dart'; import 'package:aman_kassa_flutter/redux/store.dart'; import 'package:aman_kassa_flutter/shared/app_colors.dart'; +import 'package:aman_kassa_flutter/widgets/loader/Dialogs.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -31,6 +32,7 @@ class _HomeViewState extends State { PageController pageController; int selectedTabIndex; DataService _dataService = locator(); + final GlobalKey _keyLoader = new GlobalKey(); @override @@ -41,12 +43,20 @@ class _HomeViewState extends State { pageController = new PageController(initialPage: selectedTabIndex); } + @override + void dispose() { + pageController.dispose(); + super.dispose(); + } + void _onSelectChoice(Choice choice) async { if(choice.command == 'exit') { } else if (choice.command == 'update') { + Dialogs.showLoadingDialog(context, _keyLoader); bool result = await _dataService.getDataFromServer(Redux.store.state.userState.user.token); print('result: $result'); + Navigator.of(_keyLoader.currentContext,rootNavigator: true).pop(); } } diff --git a/lib/views/home/home_view_model.dart b/lib/views/home/home_view_model.dart deleted file mode 100644 index b3a0313..0000000 --- a/lib/views/home/home_view_model.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'package:aman_kassa_flutter/core/base/base_view_model.dart'; -import 'package:aman_kassa_flutter/core/entity/Category.dart'; -import 'package:aman_kassa_flutter/core/locator.dart'; -import 'package:aman_kassa_flutter/core/models/Choice.dart'; -import 'package:aman_kassa_flutter/core/models/user.dart'; -import 'package:aman_kassa_flutter/core/route_names.dart'; -import 'package:aman_kassa_flutter/core/services/DataService.dart'; -import 'package:aman_kassa_flutter/core/services/authentication_service.dart'; -import 'package:aman_kassa_flutter/core/services/dialog_service.dart'; - -import 'package:aman_kassa_flutter/core/services/navigator_service.dart'; -import 'package:flutter/material.dart'; - -class HomeViewModel extends BaseViewModel { - NavigatorService _navigationService; - AuthenticationService _authenticationService; - DataService _dataService; - final DialogService _dialogService = locator(); - - HomeViewModel({ - @required AuthenticationService authenticationService, - @required NavigatorService navigationService, - @required DataService dataService, - }) : _authenticationService = authenticationService, - _dataService = dataService, - _navigationService = navigationService; - - User _currentUser; - User get currentUser => _currentUser; - - int _tabIndex = 0; - int get tabIndex => this._tabIndex; - set tabIndex(int index) { - this._tabIndex = index; - notifyListeners(); - } - - void onSelected(Choice choice) async { - log.i(choice.command); - if(choice.command == 'exit') { - bool result = await _authenticationService.logout(_currentUser.token); - if (result) { - _navigationService.replace(LoginViewRoute); - } - } else if (choice.command == 'update') { - log.i(_authenticationService.currentUser.token); - bool result = await _dataService.getDataFromServer(_authenticationService.currentUser.token); - log.i(result); - } - } - - PageController get pageController => this._pageController; - PageController _pageController; - set pageController(PageController pageController) { - this._pageController = pageController; - } - - List _bottomSheetElements = []; - List get bottomSheetElements => this._bottomSheetElements; - int _parentId; - void selectBottomElement(int parentId) async { -// log.i('parentId=$parentId'); -// _parentId = parentId; -// _bottomSheetElements.clear(); -// List categories = await _dataService.getCategoriesByParentId(parentId: parentId); -// List goods = await _dataService.getGoodsByCategoryId(categoryId: parentId); -// _bottomSheetElements.addAll(categories); -// _bottomSheetElements.addAll(goods); -// notifyListeners(); - } - - - - String _text; - get text => this._text; - set text(String text) => this._text = text; - - void initialize() { - - _currentUser = _authenticationService.currentUser; - } - - @override - void dispose() { - super.dispose(); - _pageController.dispose(); - } -} diff --git a/lib/views/home/tabs/AdditionalTab.dart b/lib/views/home/tabs/AdditionalTab.dart index 0066a51..7cbd189 100644 --- a/lib/views/home/tabs/AdditionalTab.dart +++ b/lib/views/home/tabs/AdditionalTab.dart @@ -1,7 +1,9 @@ import 'package:aman_kassa_flutter/redux/state/user_state.dart'; import 'package:aman_kassa_flutter/redux/store.dart'; +import 'package:aman_kassa_flutter/shared/app_colors.dart'; +import 'package:aman_kassa_flutter/shared/ui_helpers.dart'; +import 'package:aman_kassa_flutter/widgets/fields/busy_button.dart'; import 'package:flutter/material.dart'; -import 'package:aman_kassa_flutter/views/home/home_view_model.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -14,10 +16,39 @@ class AdditionalTab extends StatelessWidget { converter: (store) => store.state.userState, builder: (context, vm) { return Container( + padding: const EdgeInsets.symmetric(vertical: 15), child: Column( children: [ - Text('AdditionalTab index:$index ${vm.user.fullName} ', - style: GoogleFonts.lato(color: Colors.black87)) + verticalSpaceLarge, + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + BusyButton(title: 'Открыть смену', onPressed: null, mainColor: greenColor,), + BusyButton(title: 'Закрыть смену', onPressed: null, mainColor: redColor ,), + ], + ), + verticalSpaceLarge, + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + BusyButton(title: 'Денег в кассе', onPressed: null,), + ], + ), + verticalSpaceLarge, + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + BusyButton(title: 'Взнос наличных', onPressed: null,), + BusyButton(title: 'Снятие наличных', onPressed: null, mainColor: redColor ,), + ], + ), + verticalSpaceLarge, + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + BusyButton(title: 'Х Отчет', onPressed: null,), + ], + ) ], ), ); diff --git a/lib/views/home/tabs/CalculatorTab.dart b/lib/views/home/tabs/CalculatorTab.dart index c051ca1..0fba9c9 100644 --- a/lib/views/home/tabs/CalculatorTab.dart +++ b/lib/views/home/tabs/CalculatorTab.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:aman_kassa_flutter/views/home/home_view_model.dart'; import 'package:aman_kassa_flutter/widgets/components/calculator/calculator-buttons.dart'; import 'package:aman_kassa_flutter/widgets/components/calculator/number-display.dart'; diff --git a/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart b/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart index 654304c..c751840 100644 --- a/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart +++ b/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart @@ -1,11 +1,42 @@ +import 'package:aman_kassa_flutter/redux/actions/main_actions.dart'; +import 'package:aman_kassa_flutter/redux/store.dart'; import 'package:aman_kassa_flutter/shared/app_colors.dart'; import 'package:aman_kassa_flutter/shared/ui_helpers.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; -class ProductAddBottomSheet extends StatelessWidget { +class ProductAddBottomSheet extends StatefulWidget { final ScrollController scrollController; ProductAddBottomSheet({this.scrollController}); + + @override + _ProductAddBottomSheetState createState() => _ProductAddBottomSheetState(); +} + +class _ProductAddBottomSheetState extends State { + TextEditingController nameController; + TextEditingController countController; + TextEditingController priceController; + double sum = 0.0; + + @override + void initState() { + // TODO: implement initState + super.initState(); + nameController = new TextEditingController(); + countController = new TextEditingController(); + priceController = new TextEditingController(); + } + + @override + void dispose() { + nameController.dispose(); + countController.dispose(); + priceController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Container( @@ -15,45 +46,67 @@ class ProductAddBottomSheet extends StatelessWidget { iconTheme: IconThemeData(color: Colors.black), backgroundColor: fillColor, elevation: 3, - title: Text('Добавить товар/услугу', style: TextStyle(color: Colors.black87),), + title: Text( + 'Добавить товар/услугу', + style: TextStyle(color: Colors.black87), + ), ), body: Padding( padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10), child: ListView( - controller: scrollController, + controller: widget.scrollController, children: [ TextField( decoration: new InputDecoration( - border: new OutlineInputBorder(borderSide: new BorderSide(color: primaryColor)), - hintText: 'Введите наименовение', - labelText: 'Наименование', - prefixText: ' ', + border: new OutlineInputBorder( + borderSide: new BorderSide(color: primaryColor)), + hintText: 'Введите наименовение', + labelText: 'Наименование', + prefixText: ' ', ), + controller: nameController, ), verticalSpaceSmall, TextField( decoration: new InputDecoration( - border: new OutlineInputBorder(borderSide: new BorderSide(color: primaryColor)), - hintText: 'Введите количество', - labelText: 'Количество', - prefixText: ' ', + border: new OutlineInputBorder( + borderSide: new BorderSide(color: primaryColor)), + hintText: 'Введите количество', + labelText: 'Количество', + prefixText: ' ', ), + keyboardType: TextInputType.number, + inputFormatters: [ + WhitelistingTextInputFormatter.digitsOnly + ], + controller: countController, + onChanged: calcOnChange, ), verticalSpaceSmall, TextField( decoration: new InputDecoration( - border: new OutlineInputBorder(borderSide: new BorderSide(color: primaryColor)), + border: new OutlineInputBorder( + borderSide: new BorderSide(color: primaryColor)), hintText: 'Введите цену за единицу', labelText: 'Стоимость', prefixText: ' ', ), + keyboardType: TextInputType.number, + inputFormatters: [ + WhitelistingTextInputFormatter(RegExp("^[0-9.]*")), + ], + controller: priceController, + onChanged: calcOnChange, ), const Divider( height: 1.0, ), new ListTile( - leading: const Icon(Icons.account_balance_wallet, color: primaryColor,), - title: const Text('0,454'), + leading: const Icon( + Icons.account_balance_wallet, + color: primaryColor, + ), + title: Text(sum == 0 ? '' : sum.toString()), subtitle: const Text('Стоимость'), ), verticalSpaceMedium, @@ -61,7 +114,7 @@ class ProductAddBottomSheet extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ RawMaterialButton( - onPressed: () {}, + onPressed: submit, elevation: 2.0, fillColor: greenColor, child: Icon( @@ -73,7 +126,9 @@ class ProductAddBottomSheet extends StatelessWidget { shape: CircleBorder(), ), RawMaterialButton( - onPressed: () {}, + onPressed: () { + Navigator.pop(context); + }, elevation: 2.0, fillColor: redColor, child: Icon( @@ -92,4 +147,50 @@ class ProductAddBottomSheet extends StatelessWidget { ), ); } + + void submit() { + if (nameController.text.isEmpty || + countController.text.isEmpty || + priceController.text.isEmpty) { + _showDialog(); + } else { + Redux.store.dispatch(addCustomProductToKassaItems(nameController.text, + int.parse(countController.text), double.parse(priceController.text))); + Navigator.pop(context); + } + } + + void calcOnChange(value) { + setState(() { + sum = 0; + }); + double count = double.parse(countController.text); + double price = double.parse(priceController.text); + double result = count * price; + setState(() { + sum = ((result * 100).roundToDouble()) / 100; + }); + } + + void _showDialog() { + // flutter defined function + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: new Text("Aman Касса"), + content: new Text("Введите наименова, количество и цену"), + actions: [ + new FlatButton( + child: new Text("ОK", style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + } + } diff --git a/lib/widgets/components/calculator/calculator-button.dart b/lib/widgets/components/calculator/calculator-button.dart index 1a10148..72e1217 100644 --- a/lib/widgets/components/calculator/calculator-button.dart +++ b/lib/widgets/components/calculator/calculator-button.dart @@ -1,7 +1,12 @@ +import 'package:aman_kassa_flutter/shared/app_colors.dart'; +import 'package:aman_kassa_flutter/widgets/components/calculator/calculator.dart'; import 'package:flutter/material.dart'; typedef void CalculatorButtonTapCallback({String buttonText}); +List operationsBlue = [Calculations.ADD,Calculations.MULTIPLY,Calculations.EQUAL,Calculations.ERASE]; +List operationsRed = [Calculations.CLEAR]; + class CalculatorButton extends StatelessWidget { CalculatorButton({this.text, @required this.onTap}); @@ -14,19 +19,37 @@ class CalculatorButton extends StatelessWidget { child: Container( decoration: BoxDecoration( border: Border.all( - color: const Color.fromRGBO(0, 0, 0, 0.1), - width: 0.5, + color: Colors.black, + width: 1, ), ), child: FlatButton( onPressed: () => onTap(buttonText: text), child: Text( text, - style: TextStyle(fontSize: 25, fontWeight: FontWeight.w500), + style: TextStyle(fontSize: 25, fontWeight: FontWeight.w700, color: buildTextColor()), ), - padding: const EdgeInsets.all(15), + padding: const EdgeInsets.all(20), highlightColor: Colors.blueGrey[100], splashColor: Colors.blueAccent[100], + color: buildMainColor(), ))); } + + buildMainColor() { + if(operationsBlue.indexOf(text)>-1){ + return primaryColor; + } else if(operationsRed.indexOf(text)>-1){ + return redColor; + } + return fillColor; + } + buildTextColor() { + if(operationsBlue.indexOf(text)>-1){ + return whiteColor; + } else if(operationsRed.indexOf(text)>-1){ + return whiteColor; + } + return Colors.black; + } } diff --git a/lib/widgets/components/calculator/calculator-buttons.dart b/lib/widgets/components/calculator/calculator-buttons.dart index 9855d75..22191dd 100644 --- a/lib/widgets/components/calculator/calculator-buttons.dart +++ b/lib/widgets/components/calculator/calculator-buttons.dart @@ -8,11 +8,10 @@ class CalculatorButtons extends StatelessWidget { final CalculatorButtonTapCallback onTap; final calculatorButtonRows = [ - ['7', '8', '9', Calculations.DIVIDE], + ['7', '8', '9', Calculations.CLEAR], ['4', '5', '6', Calculations.MULTIPLY], - ['1', '2', '3', Calculations.SUBTRACT], - [Calculations.PERIOD, '0', '00', Calculations.ADD], - [Calculations.CLEAR, Calculations.EQUAL] + ['1', '2', '3', Calculations.ADD], + [Calculations.PERIOD, '0', Calculations.ERASE, Calculations.EQUAL] ]; @override diff --git a/lib/widgets/components/calculator/calculator.dart b/lib/widgets/components/calculator/calculator.dart index 6bdc1f0..306d043 100644 --- a/lib/widgets/components/calculator/calculator.dart +++ b/lib/widgets/components/calculator/calculator.dart @@ -6,13 +6,15 @@ class Calculations { static const SUBTRACT = '-'; static const ADD = '+'; static const DIVIDE = '/'; - static const CLEAR = 'CLEAR'; + static const ERASE = '<<'; + static const CLEAR = 'C'; static const EQUAL = '='; static const OPERATIONS = [ Calculations.ADD, Calculations.MULTIPLY, Calculations.SUBTRACT, Calculations.DIVIDE, + Calculations.ERASE ]; static double add(double a, double b) => a + b; diff --git a/lib/widgets/fields/busy_button.dart b/lib/widgets/fields/busy_button.dart index 1c88d1e..8b9536b 100644 --- a/lib/widgets/fields/busy_button.dart +++ b/lib/widgets/fields/busy_button.dart @@ -8,11 +8,15 @@ class BusyButton extends StatefulWidget { final String title; final Function onPressed; final bool enabled; + final Color mainColor; const BusyButton( - {@required this.title, - this.busy = false, - @required this.onPressed, - this.enabled = true}); + { + @required this.title, + this.busy = false, + @required this.onPressed, + this.enabled = true, + this.mainColor + }); @override _BusyButtonState createState() => _BusyButtonState(); @@ -33,7 +37,7 @@ class _BusyButtonState extends State { horizontal: widget.busy ? 10 : 25, vertical: widget.busy ? 10 : 15), decoration: BoxDecoration( - color: widget.enabled ? primaryColor : blueColorLigth, + color: widget.enabled ? ( widget.mainColor ?? primaryColor) : blueColorLigth, borderRadius: BorderRadius.circular(7), boxShadow: [mainShadowBox] ), diff --git a/lib/widgets/loader/Dialogs.dart b/lib/widgets/loader/Dialogs.dart new file mode 100644 index 0000000..3cbd7da --- /dev/null +++ b/lib/widgets/loader/Dialogs.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; + +class Dialogs { + static Future showLoadingDialog( + BuildContext context, GlobalKey key) async { + return showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return new WillPopScope( + onWillPop: () async => false, + child: SimpleDialog( + key: key, + backgroundColor: Colors.black54, + children: [ + Center( + child: Column(children: [ + CircularProgressIndicator(), + SizedBox(height: 10,), + Text("Please Wait....",style: TextStyle(color: Colors.blueAccent),) + ]), + ) + ])); + }); + } +} \ No newline at end of file