我在主要的全状态窗口小部件类中有一个搜索视图,在另一个窗口小部件类中有一个列表视图。 现在,当用户搜索某些内容时,我想将搜索文本传递给listview小部件以调用api。
那我该怎么办呢?
第一次打开列表时可以使用,但是当我搜索某些内容时如何再次调用它?
下面是我的代码段。
Stack(
children: <Widget>[
Flex(
direction: Axis.vertical,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Divider(
color: ColorsApp.gray,
height: 1,
),
searchView(),
Expanded(
child: OrderList(
isSearch: isSearch,
textSearch: textSearch,
onCallBack: widget.onCalBack,
),
),
],
),
],
);
立即更改搜索文字
void _onTextChange(String value) {
print(tag + "....value........" + value);
if (value == "") {
_writtingStatusController.add(true);
_customSearchViewController.add(false);
setState(() {
textSearch = "";
isSearch = true;
});
} else {
_writtingStatusController.add(false);
_customSearchViewController.add(true);
setState(() {
textSearch = value;
isSearch = true;
});
}
}
订单列表类
class OrderList extends StatefulWidget {
final String textSearch;
final bool isSearch;
final Function onCallBack;
const OrderList({
Key key,
this.textSearch,
this.onCallBack,
this.isSearch,
}) : super(key: key);
@override
_OrderListState createState() => _OrderListState();
}
答案 0 :(得分:0)
您应该从父级传递import random
import numpy as np
def add_noise(img):
'''Add random noise to an image'''
VARIABILITY = 50
deviation = VARIABILITY*random.random()
noise = np.random.normal(0, deviation, img.shape)
img += noise
np.clip(img, 0., 255.)
return img
# Prepare data-augmenting data generator
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
rescale=1./255,
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
zoom_range=0.2,
preprocessing_function=add_noise,
)
# Load a single image as our example
from keras.preprocessing import image
img_path = 'cat_by_irene_mei_flickr.png'
img = image.load_img(img_path, target_size=(299,299))
# Generate distorted images
images = [img]
img_arr = image.img_to_array(img)
img_arr = img_arr.reshape((1,) + img_arr.shape)
for batch in datagen.flow(img_arr, batch_size=1):
images.append( image.array_to_img(batch[0]) )
if len(images) >= 4:
break
# Display
import matplotlib.pyplot as plt
f, xyarr = plt.subplots(2,2)
xyarr[0,0].imshow(images[0])
xyarr[0,1].imshow(images[1])
xyarr[1,0].imshow(images[2])
xyarr[1,1].imshow(images[3])
plt.show()
方法。
onChanged
然后在父项中:
class SearchView extends StatelessWidget {
final void Function(String) onChanged;
const SearchView({Key key, this.onChanged}) : super(key: key);
@override
Widget build(BuildContext context) {
return
...
TextField(
...
onChanged: this.onChanged,
...
),
...
}
}