category_view.dart search start
parent
f4c74f8b2b
commit
6b9aa04ccc
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import 'package:satu/core/base/base_service.dart';
|
import 'package:satu/core/base/base_service.dart';
|
||||||
import 'package:satu/core/entity/category_entity.dart';
|
import 'package:satu/core/entity/category_entity.dart';
|
||||||
import 'package:satu/core/entity/goods_entity.dart';
|
import 'package:satu/core/entity/goods_entity.dart';
|
||||||
|
|
@ -39,7 +38,7 @@ class DictionaryService extends BaseService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
log.e("categories", e, stack);
|
log.e('categories', e, stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,12 +46,33 @@ class DictionaryService extends BaseService {
|
||||||
final List<Category> list = [];
|
final List<Category> list = [];
|
||||||
try {
|
try {
|
||||||
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
||||||
final List<Map<String, dynamic>> elements = await _db.queryRowsWithWhere(categoryTableName, '$categoryColumnAppCompanyId = ? and $categoryColumnParentIn = ?', [appCompanyId, parentId]);
|
final List<Map<String, dynamic>> elements = await _db.queryRowsWithWhere(
|
||||||
|
categoryTableName,
|
||||||
|
'$categoryColumnAppCompanyId = ? and $categoryColumnParentIn = ?',
|
||||||
|
[appCompanyId, parentId]);
|
||||||
for (final Map<String, dynamic> element in elements) {
|
for (final Map<String, dynamic> element in elements) {
|
||||||
list.add(Category.fromMap(element));
|
list.add(Category.fromMap(element));
|
||||||
}
|
}
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
log.e("getCategoryByParentId", e, stack);
|
log.e('getCategoryByParentId', e, stack);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Category>> getCategoriesAll() async {
|
||||||
|
final List<Category> list = [];
|
||||||
|
try {
|
||||||
|
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
||||||
|
final List<Map<String, dynamic>> elements = await _db.queryRowsWithWhere(
|
||||||
|
categoryTableName,
|
||||||
|
'$categoryColumnAppCompanyId = ? '
|
||||||
|
' order by $categoryColumnParentIn asc, $categoryColumnId asc ',
|
||||||
|
[appCompanyId]);
|
||||||
|
for (final Map<String, dynamic> element in elements) {
|
||||||
|
list.add(Category.fromMap(element));
|
||||||
|
}
|
||||||
|
} catch (e, stack) {
|
||||||
|
log.e('getCategoriesAll', e, stack);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
@ -61,12 +81,15 @@ class DictionaryService extends BaseService {
|
||||||
final List<Good> list = [];
|
final List<Good> list = [];
|
||||||
try {
|
try {
|
||||||
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
||||||
final List<Map<String, dynamic>> elements = await _db.queryRowsWithWhere(goodTableName, '$GoodColumnAppCompanyId = ? and $GoodColumnCategoryId = ?', [appCompanyId, categoryId]);
|
final List<Map<String, dynamic>> elements = await _db.queryRowsWithWhere(
|
||||||
|
goodTableName,
|
||||||
|
'$GoodColumnAppCompanyId = ? and $GoodColumnCategoryId = ?',
|
||||||
|
[appCompanyId, categoryId]);
|
||||||
for (final Map<String, dynamic> element in elements) {
|
for (final Map<String, dynamic> element in elements) {
|
||||||
list.add(Good.fromMap(element));
|
list.add(Good.fromMap(element));
|
||||||
}
|
}
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
log.e("getGoodsByCategoryId", e, stack);
|
log.e('getGoodsByCategoryId', e, stack);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
@ -75,18 +98,20 @@ class DictionaryService extends BaseService {
|
||||||
final List<Good> list = [];
|
final List<Good> list = [];
|
||||||
try {
|
try {
|
||||||
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
||||||
String where = '( $GoodColumnAppCompanyId = ? and $GoodColumnName like ? ) ';
|
String where =
|
||||||
|
'( $GoodColumnAppCompanyId = ? and $GoodColumnName like ? ) ';
|
||||||
final List args = [appCompanyId, '%$query%'];
|
final List args = [appCompanyId, '%$query%'];
|
||||||
if (_isNumericInt(query)) {
|
if (_isNumericInt(query)) {
|
||||||
where += ' or $GoodColumnEan like ?';
|
where += ' or $GoodColumnEan like ?';
|
||||||
args.add('${int.parse(query).toString()}%');
|
args.add('${int.parse(query).toString()}%');
|
||||||
}
|
}
|
||||||
final List<Map<String, dynamic>> elements = await _db.queryRowsWithWhere(goodTableName, where, args);
|
final List<Map<String, dynamic>> elements =
|
||||||
|
await _db.queryRowsWithWhere(goodTableName, where, args);
|
||||||
for (final Map<String, dynamic> element in elements) {
|
for (final Map<String, dynamic> element in elements) {
|
||||||
list.add(Good.fromMap(element));
|
list.add(Good.fromMap(element));
|
||||||
}
|
}
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
log.e("getGoodsByCategoryId", e, stack);
|
log.e('getGoodsByCategoryId', e, stack);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
@ -95,15 +120,16 @@ class DictionaryService extends BaseService {
|
||||||
final List<Good> list = [];
|
final List<Good> list = [];
|
||||||
try {
|
try {
|
||||||
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
||||||
final String where = '( $GoodColumnAppCompanyId = ? and $GoodColumnEan like ? ) ';
|
final String where =
|
||||||
|
'( $GoodColumnAppCompanyId = ? and $GoodColumnEan like ? ) ';
|
||||||
final List args = [appCompanyId, '%$code%'];
|
final List args = [appCompanyId, '%$code%'];
|
||||||
final List<Map<String, dynamic>>
|
final List<Map<String, dynamic>> elements =
|
||||||
elements = await _db.queryRowsWithWhere(goodTableName, where, args);
|
await _db.queryRowsWithWhere(goodTableName, where, args);
|
||||||
for (final Map<String, dynamic> element in elements) {
|
for (final Map<String, dynamic> element in elements) {
|
||||||
list.add(Good.fromMap(element));
|
list.add(Good.fromMap(element));
|
||||||
}
|
}
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
log.e("getGoodsByEan", e, stack);
|
log.e('getGoodsByEan', e, stack);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +164,7 @@ class DictionaryService extends BaseService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
log.e("goods", e, stack);
|
log.e('goods', e, stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ import 'package:satu/widgets/bar/products_app_bar.dart';
|
||||||
import 'package:satu/widgets/bar/products_title_bar.dart';
|
import 'package:satu/widgets/bar/products_title_bar.dart';
|
||||||
import 'package:satu/widgets/fields/input_field.dart';
|
import 'package:satu/widgets/fields/input_field.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryDictionaryView extends StatefulWidget {
|
class CategoryDictionaryView extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_CategoryDictionaryViewState createState() => _CategoryDictionaryViewState();
|
_CategoryDictionaryViewState createState() => _CategoryDictionaryViewState();
|
||||||
|
|
@ -26,7 +24,9 @@ class _CategoryDictionaryViewState extends State<CategoryDictionaryView> {
|
||||||
late TextEditingController _searchTextController;
|
late TextEditingController _searchTextController;
|
||||||
final FocusNode _searchFocusNode = new FocusNode();
|
final FocusNode _searchFocusNode = new FocusNode();
|
||||||
|
|
||||||
final List<Category> _contragents = [];
|
late List<Category> _categories = [];
|
||||||
|
|
||||||
|
late List<CategoryRowDao> items = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -38,9 +38,15 @@ class _CategoryDictionaryViewState extends State<CategoryDictionaryView> {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
initQuery();
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> initQuery() async {
|
||||||
|
_categories = await _dictionaryService.getCategoriesAll();
|
||||||
|
searchByField('');
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_searchTextController.dispose();
|
_searchTextController.dispose();
|
||||||
|
|
@ -70,12 +76,11 @@ class _CategoryDictionaryViewState extends State<CategoryDictionaryView> {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
physics: const BouncingScrollPhysics(),
|
physics: const BouncingScrollPhysics(),
|
||||||
itemCount: _contragents.length,
|
itemCount: items.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
final Category category = _contragents[index];
|
final CategoryRowDao category = items[index];
|
||||||
return const DictionaryTile(
|
return DictionaryTile(
|
||||||
title: 'category.name',
|
title: category.name, subTitle: category.parentName
|
||||||
subTitle: 'sub'
|
|
||||||
// key: Key('category_${category.id}'),
|
// key: Key('category_${category.id}'),
|
||||||
//onPress: () => () {},
|
//onPress: () => () {},
|
||||||
);
|
);
|
||||||
|
|
@ -95,13 +100,36 @@ class _CategoryDictionaryViewState extends State<CategoryDictionaryView> {
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
_searchTextController.clear();
|
_searchTextController.clear();
|
||||||
|
searchByField('');
|
||||||
}
|
}
|
||||||
|
|
||||||
void searchByField(String query) async {
|
void searchByField(String query) async {
|
||||||
|
log.i(query);
|
||||||
List<Good> goods = await _dictionaryService.getGoodsByNameOrEan(query);
|
final List<CategoryRowDao> list = [];
|
||||||
|
final Iterable<Category> 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()..name = '';
|
||||||
|
});
|
||||||
|
String parentName = category.name;
|
||||||
|
final CategoryRowDao rowDao =
|
||||||
|
CategoryRowDao(element.name, parentName, element.id);
|
||||||
|
list.add(rowDao);
|
||||||
|
});
|
||||||
setState(() {
|
setState(() {
|
||||||
goods;
|
items = list;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CategoryRowDao {
|
||||||
|
CategoryRowDao(this.name, this.parentName, this.id);
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
final String parentName;
|
||||||
|
final int? id;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue