import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:get/get.dart';
|
import 'package:zy_wms_pda/api/api_service.dart';
|
|
import '../../common/custom_search_bar.dart';
|
import '../../common/empty_count.dart';
|
import '../../common/mat_tag_card.dart';
|
import '../../common/my_sliver_persistent_header_delegate.dart';
|
import '../../common/tag_card.dart';
|
|
class MatSelectPage extends StatefulWidget {
|
const MatSelectPage({super.key});
|
|
@override
|
State<MatSelectPage> createState() => _MatSelectPageState();
|
}
|
|
class _MatSelectPageState extends State<MatSelectPage> {
|
var items = [];
|
var isTag = true;
|
|
@override
|
void initState() {
|
super.initState();
|
_getTagList(1);
|
}
|
|
void _getTagList(id) async {
|
_clickItem(id);
|
}
|
|
void _clickItem(id) async {
|
var tagList = await ApiService.tagList(id);
|
if (tagList['data'] != null && tagList['data'].length > 0) {
|
setState(() {
|
isTag = true;
|
items = tagList['data'];
|
});
|
} else {
|
var matList = await ApiService.matList(id);
|
if (matList['data'] != null && matList['data']['records'].length > 0) {
|
// print('matList: ${matList['data']['records'].length}');
|
setState(() {
|
isTag = false;
|
items = matList['data']['records'];
|
print('items');
|
});
|
}
|
}
|
}
|
|
|
void deleteItem(int index) {
|
setState(() {
|
// 删除指定索引的对象
|
items.removeAt(index);
|
});
|
}
|
Widget listItem({
|
required item
|
}) {
|
if (isTag) {
|
return TagCard(name: item['name'], parentName: item['parentName'], tagId: item['id'],onTagTap: () {
|
_clickItem(item['id']);
|
});
|
} else {
|
return MatTagCard(
|
matnr: item['matnr'],
|
maktx: item['maktx'],
|
specs: item['specs'],
|
tagText: item['matnr'],
|
onTagTap: () {
|
Get.back(result: item['matnr']);
|
}
|
);
|
}
|
}
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
appBar: AppBar(
|
title: Text('选择物料'),
|
),
|
body: CustomScrollView(
|
slivers: [
|
SliverPersistentHeader(
|
pinned: true, // 设置为true,表示吸顶效果
|
delegate: MySliverPersistentHeaderDelegate(
|
minHeight: 60, // 最小高度
|
maxHeight: 60, // 最大高度
|
child: CustomSearchBar(onTap: () {},)
|
),
|
),
|
SliverPersistentHeader(
|
pinned: true, // 设置为true,表示吸顶效果
|
delegate: MySliverPersistentHeaderDelegate(
|
minHeight: 60, // 最小高度
|
maxHeight: 60, // 最大高度
|
child: Container(
|
padding:EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
|
decoration: BoxDecoration(
|
color: Colors.white,
|
),
|
child: ElevatedButton.icon(
|
icon: Icon(Icons.reply),
|
label: Text("返回"),
|
onPressed: (){},
|
),
|
|
)
|
),
|
),
|
SliverList(
|
delegate: items.isEmpty
|
? SliverChildBuilderDelegate(
|
(context, index) {
|
print('Building item at index: $index'); // 添加调试信息
|
return EmptyCount();
|
},
|
childCount: 1, // 项目数量
|
)
|
: SliverChildBuilderDelegate(
|
(context, index) {
|
var item = items[index];
|
return listItem(item: item);
|
},
|
childCount: items.length, // 项目数量
|
),
|
),
|
|
],
|
),
|
);
|
}
|
}
|