diff --git a/lib/core/services/dictionary_service.dart b/lib/core/services/dictionary_service.dart index 2bb6f0e..215fcca 100644 --- a/lib/core/services/dictionary_service.dart +++ b/lib/core/services/dictionary_service.dart @@ -59,6 +59,24 @@ class DictionaryService extends BaseService { return list; } + Future getCategoryById(int id) async { + Category? result; + try { + final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId; + final List> elements = await _db.queryRowsWithWhere( + categoryTableName, + '$categoryColumnAppCompanyId = ? and $categoryColumnId = ?', + [appCompanyId, id]); + + for (final Map element in elements) { + result = Category.fromMap(element); + } + } catch (e, stack) { + log.e('getCategoryById', e, stack); + } + return result; + } + Future> getCategoriesAll() async { final List list = []; try { diff --git a/lib/routes/route_names.dart b/lib/routes/route_names.dart index 0ad7310..d47608a 100644 --- a/lib/routes/route_names.dart +++ b/lib/routes/route_names.dart @@ -10,3 +10,7 @@ const String paymentViewRoute = 'paymentViewRoute'; const String settingPrinterBluetoothViewRoute = 'SettingPrinterBluetoothView'; // Generate the views here + + +const String categoryEditRoute = 'categoryEditRoute'; +const String categorySelectViewRoute = 'categorySelectViewRoute'; \ No newline at end of file diff --git a/lib/routes/router.dart b/lib/routes/router.dart index 069b437..f4632b1 100644 --- a/lib/routes/router.dart +++ b/lib/routes/router.dart @@ -1,4 +1,7 @@ +import 'package:satu/views/dictionaries/category/category_edit.dart'; +import 'package:satu/views/dictionaries/category/category_select_view.dart'; +import 'package:satu/views/dictionaries/category/category_view.dart'; import 'package:satu/views/work/views/add_by_barcode/add_by_barcode_view.dart'; import 'package:satu/views/work/views/add_product/add_product_view.dart'; import 'package:satu/views/login/login_view.dart'; @@ -54,6 +57,18 @@ Route generateRoute(RouteSettings settings) { routeName: settings.name!, viewToShow: PaymentView(), ); + case categoryEditRoute: + final CategoryRowDao category = settings.arguments! as CategoryRowDao; + return _getPageRoute( + routeName: settings.name!, + viewToShow: CategoryEdit(category: category,), + ); + case categorySelectViewRoute: + return _getPageRoute( + routeName: settings.name!, + viewToShow: CategorySelectView(), + ); + // case ImageShowRoute: // ImageShowModel data = settings.arguments as ImageShowModel; // //return SlideRightRoute(widget: ImageShowContainer(data)); diff --git a/lib/views/dictionaries/category/category_edit.dart b/lib/views/dictionaries/category/category_edit.dart index 7faa20c..c7743a4 100644 --- a/lib/views/dictionaries/category/category_edit.dart +++ b/lib/views/dictionaries/category/category_edit.dart @@ -1,15 +1,139 @@ import 'package:flutter/material.dart'; +import 'package:logger/logger.dart'; +import 'package:satu/core/entity/category_entity.dart'; +import 'package:satu/core/models/dialog_models.dart'; +import 'package:satu/core/services/dialog_service.dart'; +import 'package:satu/core/services/dictionary_service.dart'; +import 'package:satu/core/services/navigator_service.dart'; +import 'package:satu/core/utils/locator.dart'; +import 'package:satu/core/utils/logger.dart'; +import 'package:satu/routes/route_names.dart'; +import 'package:satu/shared/ui_helpers.dart'; +import 'package:satu/views/dictionaries/category/category_view.dart'; +import 'package:satu/widgets/bar/products_app_bar.dart'; +import 'package:satu/widgets/buttons/busy_button.dart'; +import 'package:satu/widgets/fields/input_field.dart'; +import 'package:satu/widgets/fields/line_tile.dart'; +import 'package:satu/widgets/fields/note_text.dart'; class CategoryEdit extends StatefulWidget { - const CategoryEdit({Key? key}) : super(key: key); + const CategoryEdit({ + required this.category, + Key? key, + }) : super(key: key); + final CategoryRowDao category; @override _CategoryEditState createState() => _CategoryEditState(); } class _CategoryEditState extends State { + final NavigatorService _navigatorService = locator(); + final DictionaryService _dictionaryService = locator(); + final DialogService _dialogService = locator(); + final Logger log = getLogger('_CategoryEditState'); + late TextEditingController _controller; + + String parentCategoryName = ''; + int parentCategoryId = 0; + + @override + void initState() { + super.initState(); + if (widget.category.parentId != null) { + parentCategoryId = widget.category.parentId!; + } + _controller = TextEditingController(text: widget.category.name); + + getAndStateCategoryName(parentCategoryId); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + Future getAndStateCategoryName(int id) async { + String name = ''; + if (id == 0) { + name = 'Корневая категория'; + } else { + log.i('message $id'); + final Category? category = await _dictionaryService.getCategoryById(id); + if (category != null) { + name = category.name; + } + log.i('message $name'); + } + + setState(() { + parentCategoryName = name; + parentCategoryId = id; + }); + } + @override Widget build(BuildContext context) { - return Container(); + return Scaffold( + appBar: ProductsAppBar( + title: widget.category.id == null + ? 'Создание категории' + : 'Редактирование категории', + ), + body: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + verticalSpaceSmall, + LineTile( + parentCategoryName, + onTap: selectCategory, + labelText: 'Родительская категория', + ), + verticalSpaceSmall, + InputField( + controller: _controller, + labelText: 'Наименование', + placeholder: 'Введите наименование категории', + ), + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 45.0, vertical: 20.0), + child: BusyButton(title: 'СОХРАНИТЬ', onPressed: () {}), + ), + if (widget.category.id != null) + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 45.0, vertical: 20.0), + child: BusyButton( + title: 'УДАЛИТЬ', + onPressed: () async { + DialogResponse response = + await _dialogService.showConfirmationDialog( + title: 'Внимание', + description: + 'Вы уверены, что хотите удалить категорию?', + confirmationTitle: 'Удалить', + cancelTitle: 'Отмена'); + + return response.confirmed; + }, + isDanger: true, + ), + ), + ], + ), + ), + ); + } + + Future selectCategory() async { + final dynamic result = + await _navigatorService.push(categorySelectViewRoute); + if (result != null) { + getAndStateCategoryName(result as int); + } } } diff --git a/lib/views/dictionaries/category/category_select_view.dart b/lib/views/dictionaries/category/category_select_view.dart new file mode 100644 index 0000000..04bd12a --- /dev/null +++ b/lib/views/dictionaries/category/category_select_view.dart @@ -0,0 +1,141 @@ +import 'package:flutter/material.dart'; +import 'package:satu/core/entity/category_entity.dart'; +import 'package:satu/core/entity/goods_entity.dart'; +import 'package:satu/core/redux/actions/sell_actions.dart'; +import 'package:satu/core/redux/store.dart'; +import 'package:satu/core/services/dictionary_service.dart'; +import 'package:satu/core/services/navigator_service.dart'; +import 'package:satu/core/utils/locator.dart'; +import 'package:satu/routes/route_names.dart'; +import 'package:satu/shared/app_colors.dart'; +import 'package:satu/shared/ui_helpers.dart'; +import 'package:satu/views/dictionaries/component/dictionary_list_tile.dart'; +import 'package:satu/widgets/bar/products_app_bar.dart'; +import 'package:satu/widgets/bar/products_title_bar.dart'; +import 'package:satu/widgets/fields/input_field.dart'; +import 'package:satu/widgets/fields/line_checkbox.dart'; + +import 'category_view.dart'; + +class CategorySelectView extends StatefulWidget { + @override + _CategorySelectViewState createState() => _CategorySelectViewState(); +} + +class _CategorySelectViewState extends State { + final DictionaryService _dictionaryService = locator(); + final NavigatorService _navigatorService = locator(); + late TextEditingController _searchTextController; + final FocusNode _searchFocusNode = FocusNode(); + + late List _categories = []; + + late List items = []; + + @override + void initState() { + _searchTextController = TextEditingController(); + _searchTextController.addListener(() { + if (_searchTextController.text.isNotEmpty) { + searchByField(_searchTextController.text); + } else { + reset(); + } + }); + initQuery(); + super.initState(); + } + + Future initQuery() async { + _categories = await _dictionaryService.getCategoriesAll(); + searchByField(''); + } + + @override + void dispose() { + _searchTextController.dispose(); + _searchFocusNode.dispose(); + super.dispose(); + } + + Future handlerCategory(int id) async { + _navigatorService.pop(id); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: const ProductsAppBar( + title: 'Выбор категории', + ), + body: Column( + children: [ + InputField( + placeholder: 'Поиск по наименованию категории', + search: true, + controller: _searchTextController, + fieldFocusNode: _searchFocusNode, + ), + verticalSpaceMedium, + LineCheckBox( + 'Корневая категория', + value: true, + labelText: 'По умолчанию', + onTap: () => handlerCategory(0), + ), + const ProductsTitleBarBar(title: 'Выберите категорию'), + Expanded( + child: ListView.separated( + physics: const BouncingScrollPhysics(), + itemCount: items.length, + itemBuilder: (BuildContext context, int index) { + final CategoryRowDao category = items[index]; + return DictionaryTile( + title: category.name, + subTitle: category.parentName.isEmpty + ? 'Корневая категория' + : 'Родитель: ${category.parentName}', + key: Key('category_${category.id}'), + onPress: () => handlerCategory(category.id!), + ); + }, + separatorBuilder: (BuildContext context, int index) { + return const Divider( + height: 1.0, + color: disableColor, + ); + }, + ), + ), + ], + ), + ); + } + + void reset() { + _searchTextController.clear(); + searchByField(''); + } + + void searchByField(String query) async { + final List list = []; + final Iterable filtered = query == '' + ? _categories + : _categories.where((element) => + element.name.toLowerCase().contains(query.toLowerCase())); + filtered.forEach((element) { + final Category category = _categories + .firstWhere((parent) => parent.id == element.parentId, orElse: () { + return Category(); + }); + final String parentName = category.name; + final CategoryRowDao rowDao = CategoryRowDao( + element.name, parentName, element.id, + parentId: element.parentId); + list.add(rowDao); + }); + setState(() { + items = list; + }); + } +} diff --git a/lib/views/dictionaries/category/category_view.dart b/lib/views/dictionaries/category/category_view.dart index c94c505..5d7f77c 100644 --- a/lib/views/dictionaries/category/category_view.dart +++ b/lib/views/dictionaries/category/category_view.dart @@ -6,6 +6,7 @@ import 'package:satu/core/redux/store.dart'; import 'package:satu/core/services/dictionary_service.dart'; import 'package:satu/core/services/navigator_service.dart'; import 'package:satu/core/utils/locator.dart'; +import 'package:satu/routes/route_names.dart'; import 'package:satu/shared/app_colors.dart'; import 'package:satu/shared/ui_helpers.dart'; import 'package:satu/views/dictionaries/component/dictionary_list_tile.dart'; @@ -76,13 +77,14 @@ class _CategoryDictionaryViewState extends State { itemBuilder: (BuildContext context, int index) { final CategoryRowDao category = items[index]; return DictionaryTile( - title: category.name, - subTitle: category.parentName.isEmpty - ? 'Корневая категория' - : 'Родитель: ${category.parentName}' - // key: Key('category_${category.id}'), - //onPress: () => () {}, - ); + title: category.name, + subTitle: category.parentName.isEmpty + ? 'Корневая категория' + : 'Родитель: ${category.parentName}', + key: Key('category_${category.id}'), + onPress: () => _navigatorService.push(categoryEditRoute, + arguments: category), + ); }, separatorBuilder: (BuildContext context, int index) { return const Divider( @@ -94,6 +96,16 @@ class _CategoryDictionaryViewState extends State { ), ], ), + floatingActionButton: FloatingActionButton( + elevation: 2, + onPressed: () => locator() + .push(categoryEditRoute, arguments: CategoryRowDao('', '', null)), + child: const Icon( + Icons.add_rounded, + size: 34.0, + color: whiteColor, + ), + ), ); } @@ -114,9 +126,10 @@ class _CategoryDictionaryViewState extends State { .firstWhere((parent) => parent.id == element.parentId, orElse: () { return Category(); }); - String parentName = category.name; - final CategoryRowDao rowDao = - CategoryRowDao(element.name, parentName, element.id); + final String parentName = category.name; + final CategoryRowDao rowDao = CategoryRowDao( + element.name, parentName, element.id, + parentId: element.parentId); list.add(rowDao); }); setState(() { @@ -126,9 +139,10 @@ class _CategoryDictionaryViewState extends State { } class CategoryRowDao { - CategoryRowDao(this.name, this.parentName, this.id); + CategoryRowDao(this.name, this.parentName, this.id, { this.parentId = 0}); final String name; final String parentName; final int? id; + final int? parentId; } diff --git a/lib/views/dictionaries/component/dictionary_list_tile.dart b/lib/views/dictionaries/component/dictionary_list_tile.dart index 742e47b..81eb705 100644 --- a/lib/views/dictionaries/component/dictionary_list_tile.dart +++ b/lib/views/dictionaries/component/dictionary_list_tile.dart @@ -2,30 +2,42 @@ import 'package:flutter/material.dart'; import 'package:satu/shared/app_colors.dart'; class DictionaryTile extends StatelessWidget { - const DictionaryTile({required this.title, this.subTitle, Key? key}) - : super(key: key); + const DictionaryTile({ + required this.title, + Key? key, + this.subTitle, + this.onPress, + }) : super(key: key); final String title; final String? subTitle; + final Function()? onPress; @override Widget build(BuildContext context) { return Container( decoration: const BoxDecoration(color: whiteColor), - child: Padding( - padding: const EdgeInsets.symmetric( horizontal: 15.0 , vertical: 10.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - title, - style: const TextStyle(fontSize: 12), + child: Material( + color: Colors.transparent, + child: InkWell( + onTap: onPress, + child: Padding( + padding: + const EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + title, + style: const TextStyle(fontSize: 12, color: textColor), + ), + if (subTitle != null && subTitle!.isNotEmpty) + Text(subTitle!, + style: const TextStyle( + fontSize: 10, color: placeholderColor)), + ], ), - if (subTitle != null && subTitle!.isNotEmpty) - Text(subTitle!, - style: - const TextStyle(fontSize: 10, color: placeholderColor)), - ], + ), ), ), ); diff --git a/lib/views/work/tabs/component/product_list_item.dart b/lib/views/work/tabs/component/product_list_item.dart index 72b61f2..f7e007c 100644 --- a/lib/views/work/tabs/component/product_list_item.dart +++ b/lib/views/work/tabs/component/product_list_item.dart @@ -66,26 +66,40 @@ class _ProductListItemState extends State { ), direction: DismissDirection.endToStart, confirmDismiss: (DismissDirection direction) async { - return await showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Внимание'), - content: Text('Удалить товар ' - '"${widget.name}"' - ' - ${widget.count} ед. ?'), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(true), - child: const Text('Удалить')), - TextButton( - onPressed: () => Navigator.of(context).pop(false), - child: const Text('Отмена'), - ), - ], - ); - }, + DialogResponse response = await _dialogService.showConfirmationDialog( + title: 'Внимание', + description: 'Удалить товар' + '"${widget.name}"' + ' - ${widget.count} ед. ?', + confirmationTitle: 'Удалить', + cancelTitle: 'Отмена' ); + + return response.confirmed; + + // return await showDialog( + // context: context, + // builder: (BuildContext context) { + // + // + // + // return AlertDialog( + // title: const Text('Внимание'), + // content: Text('Удалить товар ' + // '"${widget.name}"' + // ' - ${widget.count} ед. ?'), + // actions: [ + // TextButton( + // onPressed: () => Navigator.of(context).pop(true), + // child: const Text('Удалить')), + // TextButton( + // onPressed: () => Navigator.of(context).pop(false), + // child: const Text('Отмена'), + // ), + // ], + // ); + // }, + // ); }, onDismissed: (direction) { Redux.store! diff --git a/lib/views/work/views/payment/payment_view.dart b/lib/views/work/views/payment/payment_view.dart index b428693..2be89e4 100644 --- a/lib/views/work/views/payment/payment_view.dart +++ b/lib/views/work/views/payment/payment_view.dart @@ -5,6 +5,7 @@ import 'package:satu/core/redux/state/sell_state.dart'; import 'package:satu/core/redux/store.dart'; import 'package:satu/core/utils/utils_parse.dart'; import 'package:satu/shared/app_colors.dart'; +import 'package:satu/views/dictionaries/category/category_view.dart'; import 'package:satu/views/work/views/payment/component/combine_dock.dart'; import 'package:satu/widgets/bar/products_app_bar.dart'; import 'package:satu/widgets/bar/products_header_bar.dart'; @@ -14,6 +15,7 @@ import 'package:satu/widgets/fields/input_field.dart'; import 'package:satu/widgets/fields/line_checkbox.dart'; class PaymentView extends StatefulWidget { + const PaymentView(); @override _PaymentViewState createState() => _PaymentViewState(); } diff --git a/lib/widgets/bar/products_title_bar.dart b/lib/widgets/bar/products_title_bar.dart index c7057c5..f405f4b 100644 --- a/lib/widgets/bar/products_title_bar.dart +++ b/lib/widgets/bar/products_title_bar.dart @@ -3,64 +3,61 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:satu/core/redux/actions/sell_actions.dart'; import 'package:satu/core/redux/store.dart'; import 'package:satu/shared/app_colors.dart'; -import 'package:satu/shared/shared_styles.dart'; -import 'package:satu/widgets/dialog/modal_select_dialog.dart'; class ProductsTitleBarBar extends StatelessWidget { + const ProductsTitleBarBar( + {required this.title , Key? key, this.itemsExist = false}) + : super(key: key); + final bool itemsExist; final String title; - const ProductsTitleBarBar( - {Key? key, this.itemsExist = false, required this.title}) - : super(key: key); @override Widget build(BuildContext context) { - return Container( - child: Padding( - padding: EdgeInsets.only(left: 15.w, right: 5.w, top: 30.w), - child: Row( - children: [ - Expanded( - child: Padding( - padding: EdgeInsets.symmetric(vertical: 10.w), - child: Text( - title, - style: TextStyle(fontSize: 16.sp, color: placeholderColor), - ), - )), - if (itemsExist) - TextButton( - onPressed: () async { - final bool? result = await showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Внимание'), - content: const Text('Удалить все товары из списка'), - actions: [ - TextButton( - onPressed: () => - Navigator.of(context).pop(true), - child: const Text('Удалить')), - TextButton( - onPressed: () => Navigator.of(context).pop(false), - child: const Text('Отмена'), - ), - ], - ); - }, - ); - if (result == true) { - Redux.store!.dispatch(removeAllSellData); - } - }, - child: Text( - 'Удалить все', - style: TextStyle(fontSize: 16.sp, color: dangerColor), - )) - ], - ), + return Padding( + padding: const EdgeInsets.only(left: 15, right: 5, top: 15), + child: Row( + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 10), + child: Text( + title, + style: const TextStyle(fontSize: 12, color: placeholderColor), + ), + )), + if (itemsExist) + TextButton( + onPressed: () async { + final bool? result = await showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Внимание'), + content: const Text('Удалить все товары из списка'), + actions: [ + TextButton( + onPressed: () => + Navigator.of(context).pop(true), + child: const Text('Удалить')), + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: const Text('Отмена'), + ), + ], + ); + }, + ); + if (result == true) { + Redux.store!.dispatch(removeAllSellData); + } + }, + child: Text( + 'Удалить все', + style: TextStyle(fontSize: 16.sp, color: dangerColor), + )) + ], ), ); } diff --git a/lib/widgets/buttons/busy_button.dart b/lib/widgets/buttons/busy_button.dart index 7916255..10eb081 100644 --- a/lib/widgets/buttons/busy_button.dart +++ b/lib/widgets/buttons/busy_button.dart @@ -10,14 +10,16 @@ class BusyButton extends StatefulWidget { final String title; final Function onPressed; final bool enabled; - final Color? mainColor; + final bool isCancel; + final bool isDanger; const BusyButton({ required this.title, this.busy = false, required this.onPressed, this.enabled = true, - this.mainColor, + this.isCancel = false, + this.isDanger = false, }); @override @@ -30,7 +32,8 @@ class _BusyButtonState extends State { return AnimatedContainer( duration: const Duration(milliseconds: 300), decoration: BoxDecoration( - gradient: primaryGradient, + gradient: widget.isCancel || widget.isDanger ? null : primaryGradient, + color: widget.isCancel || widget.isDanger ? whiteColor : null, borderRadius: BorderRadius.circular(5), boxShadow: [buttonShadowBox]), child: Material( @@ -47,9 +50,9 @@ class _BusyButtonState extends State { ? Text( widget.title, textAlign: TextAlign.center, - style: const TextStyle( + style: TextStyle( fontWeight: FontWeight.w400, - color: blackColor, + color: widget.isDanger ? dangerColor : blackColor, fontSize: 12), //minFontSize: 2, maxLines: 1, diff --git a/lib/widgets/dialog/dialog_manager.dart b/lib/widgets/dialog/dialog_manager.dart index 5b104c3..57b0b1d 100644 --- a/lib/widgets/dialog/dialog_manager.dart +++ b/lib/widgets/dialog/dialog_manager.dart @@ -50,38 +50,59 @@ class _DialogManagerState extends State { showDialog( context: context, builder: (BuildContext context) => AlertDialog( + backgroundColor: backgroundColor, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(5.0), ), actionsPadding: const EdgeInsets.only(right: 15, bottom: 5), - title: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - request.title, - style: const TextStyle(fontWeight: FontWeight.bold), - ), - //Divider(), - ], - ), - content: Text(request.description), - actions: [ - if (isConfirmationDialog) - TextButton( - onPressed: () { - _dialogService - .dialogComplete(DialogResponse(confirmed: false)); - }, - child: Text(request.cancelTitle!), - ), - TextButton( - onPressed: () { - _dialogService - .dialogComplete(DialogResponse(confirmed: true)); - }, - child: Text(request.buttonTitle), + content: SizedBox( + width: ScreenUtil().setWidth(ScreenUtil().screenWidth * 0.9), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + verticalSpaceSmall, + Text( + request.description, + style: const TextStyle(fontSize: 12), + ), + verticalSpaceSmall, + const Divider(), + verticalSpaceSmall, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: BusyButton( + isDanger: true, + title: request.buttonTitle.toUpperCase(), + onPressed: () { + final String _price = _controllerPrice.text; + final String _count = _controllerCount.text; + _dialogService.dialogComplete(DialogResponse( + confirmed: true, + responsePrice: _price.replaceAll(',', '.'), + responseCount: _count.replaceAll(',', '.'))); + }, + ), + ), + horizontalSpaceMedium, + if (isConfirmationDialog) + Expanded( + child: BusyButton( + isCancel: true, + onPressed: () { + _dialogService.dialogComplete( + DialogResponse(confirmed: false)); + }, + //color: redColor, + title: request.cancelTitle!.toUpperCase(), + ), + ), + ], + ) + ], ), - ], + ), )); } diff --git a/lib/widgets/fields/line_checkbox.dart b/lib/widgets/fields/line_checkbox.dart index 82de0b3..79819fb 100644 --- a/lib/widgets/fields/line_checkbox.dart +++ b/lib/widgets/fields/line_checkbox.dart @@ -1,49 +1,65 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:satu/shared/app_colors.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'note_text.dart'; + class LineCheckBox extends StatelessWidget { - const LineCheckBox(this.text, { required this.value }); + const LineCheckBox(this.text, + {required this.value, this.labelText, this.onTap}); + final String text; final bool value; + final String? labelText; + final Function()? onTap; @override Widget build(BuildContext context) { - return Container( - decoration: const BoxDecoration( - color: whiteColor - ), - child: Material( - color: Colors.transparent, - child: InkWell( - onTap: () {}, - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 12.w), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - text, - style: TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.normal, - ), - ), - SizedBox( - width: 20.w, - child: Visibility( - visible: value, - child: const Icon( - Icons.check, - color: primaryColor, + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (labelText != null) + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 14.0, vertical: 5.0), + child: NoteText(labelText ?? ''), + ), + Container( + decoration: const BoxDecoration(color: whiteColor), + child: Material( + color: Colors.transparent, + child: InkWell( + onTap: onTap, + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 12.w), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + text, + style: TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.normal, + ), ), - ), - ) - ], + SizedBox( + width: 20.w, + child: Visibility( + visible: value, + child: const Icon( + Icons.check, + color: primaryColor, + ), + ), + ) + ], + ), + ), ), ), ), - ), + ], ); } } diff --git a/lib/widgets/fields/line_tile.dart b/lib/widgets/fields/line_tile.dart new file mode 100644 index 0000000..f911624 --- /dev/null +++ b/lib/widgets/fields/line_tile.dart @@ -0,0 +1,61 @@ +import 'package:flutter/material.dart'; +import 'package:satu/shared/app_colors.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +import 'note_text.dart'; + +class LineTile extends StatelessWidget { + const LineTile(this.text, { required this.onTap, this.labelText }); + final String text; + final String? labelText; + final Function() onTap; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (labelText != null) + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 14.0, vertical: 5.0), + child: NoteText(labelText ?? ''), + ), + Container( + decoration: const BoxDecoration( + color: whiteColor + ), + child: Material( + color: Colors.transparent, + child: InkWell( + onTap: onTap, + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 12.w), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + text, + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.normal, + color: textColor + ), + ), + SizedBox( + width: 20, + child: const Icon( + Icons.chevron_right, + color: textColor, + ), + ) + ], + ), + ), + ), + ), + ), + ], + ); + } +}