refactoring ui

null-safety-migration
suvaissov 2021-07-02 13:58:30 +06:00
parent 9b866298f5
commit 6590fba912
18 changed files with 151 additions and 175 deletions

View File

@ -14,7 +14,7 @@ const String GoodColumnAppCompanyId = 'app_company_id';
class Good {
int? id;
int? categoryId;
String? name;
String name = '';
String? ean;
int? articul;
num? price;

View File

@ -12,7 +12,7 @@
class GoodResponse {
int? id;
int? categoryId;
String? name;
String name = '';
String? ean;
int? articul;
int? price;

View File

@ -3,7 +3,7 @@ class ProductDao {
int? categoryId;
num? count;
num? price;
String? productName;
String productName = '';
String? categoryName;
String? eanCode;
int? article;

View File

@ -2,7 +2,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:satu/views/work/tabs/component/products_app_bar.dart';
import 'package:satu/widgets/bar/products_app_bar.dart';
import 'package:satu/widgets/tools/app_barcode_scanner_widget.dart';
class AddByBarcodeView extends StatefulWidget {

View File

@ -9,7 +9,8 @@ import 'package:satu/core/utils/locator.dart';
import 'package:satu/shared/app_colors.dart';
import 'package:satu/shared/ui_helpers.dart';
import 'package:satu/views/add_product/component/add_category_list_item.dart';
import 'package:satu/views/add_product/component/app_bar.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 'component/add_product_list_item.dart';
@ -62,44 +63,42 @@ class _AddProductViewState extends State<AddProductView> {
int catSize = _categories?.length ?? 0;
int goodSize = _goods?.length ?? 0;
return Scaffold(
appBar: AddProductAppBar(title: 'Товар', actions: actions(),),
appBar: ProductsAppBar( title: 'Категория',),
body: Column(
children: [
InputField(placeholder: 'Поиск по наименованию и коду товара',
InputField(placeholder: 'Поиск по наименованию или коду товара',
search: true,
controller: _searchTextController,
fieldFocusNode: _searchFocusNode,),
verticalSpaceTiny,
ProductsTitleBarBar(title: goodSize > 0 ? 'Выберите товар' : 'Выберите категорию',),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: catSize + goodSize,
itemBuilder: (BuildContext context, int index) {
if (index < catSize) {
Category category = _categories![index];
return AddCategoryListItem(
name: category.name,
isOdd: index % 2 == 0,
key: Key('category_${category.id}'),
onPress: () => onCategoryPress(category),
);
}
Good good = _goods![index - catSize];
return AddProductListItem(
key: Key('product_${good.id}'),
ean: good.ean,
isOdd: index % 2 == 0,
name: good.name,
price: good.price,
categoryName: _history?.last?.name,
onPress: () {
onGoodPress(good);
} ,
child: ListView.separated(
physics: BouncingScrollPhysics(),
itemCount: catSize + goodSize,
itemBuilder: (BuildContext context, int index) {
if (index < catSize) {
Category category = _categories![index];
return AddCategoryListItem(
name: category.name,
key: Key('category_${category.id}'),
onPress: () => onCategoryPress(category),
);
},
),
}
Good good = _goods![index - catSize];
return AddProductListItem(
key: Key('product_${good.id}'),
ean: good.ean,
name: good.name,
price: good.price,
categoryName: _history?.last?.name,
onPress: () {
onGoodPress(good);
} ,
);
}, separatorBuilder: (BuildContext context, int index) {
return Divider(height: 1.0, color: disableColor,);
},
),
),
@ -118,18 +117,6 @@ class _AddProductViewState extends State<AddProductView> {
_navigatorService.pop();
}
List<Widget> actions() {
return [
if(_history!.length > 1)
TextButton(onPressed: () {
_history!.removeLast();
navigateCategory(_history!.last.id!);
}, child: Text('Назад', style: TextStyle(color: Colors.black),),),
TextButton(onPressed: reset, child: Text('Сбросить', style: TextStyle(color: Colors.black),),)
];
}
void reset() {
_history = [Category()
..id = 0

View File

@ -6,10 +6,9 @@ import 'package:satu/shared/ui_helpers.dart';
class AddCategoryListItem extends StatelessWidget {
final String? name;
final bool? isOdd;
final Function? onPress;
const AddCategoryListItem({Key? key, this.name, this.isOdd, this.onPress }) : super(key: key);
const AddCategoryListItem({Key? key, this.name, this.onPress }) : super(key: key);
@override
Widget build(BuildContext context) {
@ -32,7 +31,6 @@ class AddCategoryListItem extends StatelessWidget {
)
),
),
tileColor: !isOdd! ? whiteColor : backgroundColor,
trailing: Icon(
Icons.arrow_right,
color: primaryColor,

View File

@ -1,63 +1,56 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:satu/shared/app_colors.dart';
import 'package:satu/shared/shared_styles.dart';
import 'package:satu/shared/ui_helpers.dart';
import 'package:satu/widgets/ui/product_title_widget.dart';
class AddProductListItem extends StatelessWidget {
final String? name;
final String name;
final String? ean;
final String? categoryName;
final num? price;
final num? count;
final bool? isOdd;
final Function? onPress;
const AddProductListItem({Key? key, this.name, this.ean, this.categoryName, this.price, this.count, this.isOdd, this.onPress}) : super(key: key);
const AddProductListItem({Key? key, required this.name, this.ean, this.categoryName, this.price, this.count, this.onPress}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
return Material(
color: Colors.transparent,
child: InkWell(
onTap: () => onPress!(),
contentPadding: const EdgeInsets.symmetric( horizontal: 8.0 ,vertical: 4.0 ),
title: Padding(
padding: const EdgeInsets.all(4.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(name! , style: TextStyle(
fontWeight: FontWeight.w600, color: Colors.black, fontSize: 15), overflow: TextOverflow.ellipsis, maxLines: 2,),
verticalSpaceTiny,
if(ean!=null)
Text('Штрих-код: $ean' , style: TextStyle(
fontWeight: FontWeight.w600, color: Colors.black, fontSize: 12),),
if(categoryName!=null)
Text(categoryName!, style: TextStyle(
fontWeight: FontWeight.w600, color: Colors.black, fontSize: 12),),
],
child: Container(
decoration: BoxDecoration(
color: whiteColor
),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 3,
child: ProductTitleWidget( name: name, ean: ean, categoryName: categoryName, ),
),
),
Flexible(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('${price}', style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold ),),
],
Flexible(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('${price}', style: TextStyle( fontSize: ScreenUtil().setSp(18.0), fontWeight: FontWeight.bold ),),
],
),
),
),
],
],
),
),
),
tileColor: !isOdd! ? whiteColor : backgroundColor,
),
);
}

View File

@ -1,26 +0,0 @@
import 'package:flutter/material.dart';
import 'package:satu/core/services/navigator_service.dart';
import 'package:satu/core/utils/locator.dart';
import 'package:satu/shared/app_colors.dart';
class AddProductAppBar extends StatelessWidget implements PreferredSizeWidget {
final String? title;
final List<Widget>? actions;
const AddProductAppBar({Key? key, this.title, this.actions}) : super(key: key);
@override
Widget build(BuildContext context) {
return AppBar(
title: Text(title!, style: const TextStyle(fontWeight: FontWeight.w700, color: Colors.black, fontSize: 25)),
backgroundColor: Colors.transparent,
elevation: 0.0,
actions: actions
,
);
}
@override
Size get preferredSize {
return new Size.fromHeight(60.0);
}
}

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.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/views/work/tabs/component/products_app_bar.dart';
import 'package:satu/widgets/bar/products_app_bar.dart';
import 'component/setting_item.dart';

View File

@ -3,7 +3,7 @@ import 'package:satu/core/services/navigator_service.dart';
import 'package:satu/core/utils/locator.dart';
import 'package:satu/shared/shared_styles.dart';
import 'component/products_app_bar.dart';
import '../../../widgets/bar/products_app_bar.dart';
class BuyView extends StatelessWidget {
@override

View File

@ -10,9 +10,10 @@ import 'package:satu/shared/app_colors.dart';
import 'package:satu/shared/shared_styles.dart';
import 'package:satu/shared/ui_helpers.dart';
import 'package:satu/views/add_by_barcode/add_by_barcode_view.dart';
import 'package:satu/widgets/ui/product_title_widget.dart';
class ProductListItem extends StatefulWidget {
final String? name;
final String name;
final String? ean;
final String? categoryName;
final num? price;
@ -21,7 +22,7 @@ class ProductListItem extends StatefulWidget {
final int? transactionId;
const ProductListItem(
{Key? key, this.name, this.ean, this.categoryName, this.price, this.count, this.isOdd, this.transactionId})
{Key? key, this.name = '', this.ean, this.categoryName, this.price, this.count, this.isOdd, this.transactionId})
: super(key: key);
@override
@ -73,7 +74,7 @@ class _ProductListItemState extends State<ProductListItem> {
print(direction);
Redux.store!.dispatch(removeSellItem(transactionId: this.widget.transactionId!));
},
key: Key(widget.name ?? ''),
key: Key(widget.name ),
child: ListTile(
//onTap: () => _onItemTapped(context),
onTap: () {},
@ -83,27 +84,7 @@ class _ProductListItemState extends State<ProductListItem> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.name ?? '',
style: TextStyle(fontSize: 12.sp, color: textColor),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
verticalSpaceTiny,
Text(
'Штрих-код: ${widget.ean}',
style: TextStyle(color: placeholderColor, fontSize: 8.sp),
),
if (widget.categoryName != null)
Text(
'Категория: ${widget.categoryName}',
style: TextStyle(color: placeholderColor, fontSize: 8.sp),
)
],
),
child: ProductTitleWidget(name: widget.name, ean: widget.ean, categoryName: widget.categoryName, ),
),
SizedBox(
width: 100.w,
@ -131,7 +112,7 @@ class _ProductListItemState extends State<ProductListItem> {
},
child: Container(
decoration: BoxDecoration(
color: whiteColor,
//color: whiteColor,
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
border: Border.all(width: 1.0.sp, color: successColor)),
child: Icon(
@ -171,7 +152,7 @@ class _ProductListItemState extends State<ProductListItem> {
},
child: Container(
decoration: BoxDecoration(
color: whiteColor,
//color: whiteColor,
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
border: Border.all(
width: 1.0.sp, color: widget.count! <= 1.0 ? disableColor : dangerColor)),
@ -195,3 +176,5 @@ class _ProductListItemState extends State<ProductListItem> {
);
}
}

View File

@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:satu/views/work/tabs/component/products_app_bar.dart';
import 'package:satu/widgets/bar/products_app_bar.dart';
import 'component/custom_field.dart';
import 'component/option_pill.dart';

View File

@ -14,9 +14,9 @@ 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/work/tabs/component/product_list_item.dart';
import 'package:satu/views/work/tabs/component/products_app_bar.dart';
import 'package:satu/views/work/tabs/component/products_header_bar.dart';
import 'package:satu/views/work/tabs/component/products_title_bar.dart';
import 'package:satu/widgets/bar/products_app_bar.dart';
import 'package:satu/widgets/bar/products_header_bar.dart';
import 'package:satu/widgets/bar/products_title_bar.dart';
import 'package:satu/views/work/tabs/utils/ProductUtils.dart';
import 'component/contagent_select_bar.dart';
@ -43,7 +43,7 @@ class SellView extends StatelessWidget {
ContragentSelectBar(
value: 'Частное лицо',
),
Visibility(child: ProductsTitleBarBar(itemsExist: true), visible: state.items!.isNotEmpty,),
Visibility(child: ProductsTitleBarBar(itemsExist: true, title: 'Товары',), visible: state.items!.isNotEmpty,),
ListView.separated(
shrinkWrap: true,
physics: BouncingScrollPhysics(),

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:satu/core/services/navigator_service.dart';
import 'package:satu/core/utils/locator.dart';
import 'package:satu/shared/app_colors.dart';
import 'package:satu/views/work/tabs/component/products_header_bar.dart';
import 'package:satu/widgets/bar/products_header_bar.dart';
class ProductsAppBar extends StatelessWidget implements PreferredSizeWidget {
final String? title;

View File

@ -8,8 +8,9 @@ import 'package:satu/widgets/dialog/modal_select_dialog.dart';
class ProductsTitleBarBar extends StatelessWidget {
final bool itemsExist;
final String title;
const ProductsTitleBarBar({Key? key, required this.itemsExist}) : super(key: key);
const ProductsTitleBarBar({Key? key, this.itemsExist = false, required this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -20,9 +21,9 @@ class ProductsTitleBarBar extends StatelessWidget {
children: [
Expanded(
child: Padding(
padding: EdgeInsets.symmetric( vertical: 16.w ),
padding: EdgeInsets.symmetric( vertical: 10.w ),
child: Text(
'Товары',
title,
style: TextStyle(fontSize: ScreenUtil().setSp(14), color: placeholderColor),
),
)),

View File

@ -54,7 +54,7 @@ class InputField extends StatefulWidget {
class _InputFieldState extends State<InputField> {
late bool isPassword;
late bool isSearch;
double fieldHeight = 45;
double fieldHeight = 40;
@override
void initState() {
@ -87,6 +87,29 @@ class _InputFieldState extends State<InputField> {
widget.isReadOnly ? disabledFieldDecoration : fieldDecoration,
child: Row(
children: <Widget>[
GestureDetector(
onTap: () {
if(isSearch) {
widget.fieldFocusNode!.requestFocus();
} else {
setState(() {
isSearch = !isSearch;
});
FocusScope.of(context).requestFocus(new FocusNode()); //remove focus
WidgetsBinding.instance!.addPostFrameCallback((_) => widget.controller.clear()); // clear content
}
},
child: widget.search
? Container(
width: fieldHeight,
height: fieldHeight,
alignment: Alignment.center,
child: Icon(isSearch
? Icons.search
: Icons.search_off, color: placeholderColor))
: Container(),
),
Expanded(
child: TextFormField(
style: TextStyle( color: textColor, fontSize: widget.smallVersion ? ScreenUtil().setSp(12) : ScreenUtil().setSp(15) ),
@ -135,28 +158,6 @@ class _InputFieldState extends State<InputField> {
: Icons.visibility_off, color: textColor))
: Container(),
),
GestureDetector(
onTap: () {
if(isSearch) {
widget.fieldFocusNode!.requestFocus();
} else {
FocusScope.of(context).requestFocus(new FocusNode()); //remove focus
WidgetsBinding.instance!.addPostFrameCallback((_) => widget.controller.clear()); // clear content
}
setState(() {
isSearch = !isSearch;
});
},
child: widget.search
? Container(
width: fieldHeight,
height: fieldHeight,
alignment: Alignment.center,
child: Icon(isSearch
? Icons.search
: Icons.search_off, color: textColor))
: Container(),
),
],
),
),

View File

@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:satu/shared/app_colors.dart';
import 'package:satu/shared/ui_helpers.dart';
import 'package:satu/views/work/tabs/component/product_list_item.dart';
class ProductTitleWidget extends StatelessWidget {
const ProductTitleWidget({Key? key, required this.name, this.ean, this.categoryName}) : super(key: key);
final String name;
final String? ean;
final String? categoryName;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: TextStyle(fontSize: 12.sp, color: textColor),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
verticalSpaceTiny,
if (ean != null)
Text(
'Штрих-код: ${ean}',
style: TextStyle(color: placeholderColor, fontSize: 8.sp),
),
if (categoryName != null)
Text(
'Категория: ${categoryName}',
style: TextStyle(color: placeholderColor, fontSize: 8.sp),
)
],
);
}
}