尝试学习 BLoCs 我想出了这个问题。我有一些代码,我在其中生成了一些带有 BLoC 模式的按钮。但是,我不知道如何使用dispatch(event)方法更新特定的按钮属性。如何将参数传递给事件ChangeSomeValues?
使用 BLoC 的部分
BlocBuilder(
bloc: myBloc,
builder: (context, state) {
return ListView.builder(
itemCount: state.buttonList.length,
itemBuilder: (context, index) {
return MyButton(
label: buttonList[index].label,
value: buttonList[index].value,
onPressed: myBloc.dispatch(ChangeSomeValues()),
);
}
);
}
),
Run Code Online (Sandbox Code Playgroud)
MyBloc.dart
class MyBloc extends Bloc<MyEvent, MyState> {
@override
Stream<MyState> mapEventToState(MyEvent event) async* {
if (event is ChangeSomeValues) {
... modify specific parameters in list here ...
yield MyState1(modifiedList);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道如何使用事件来更改值,但我找不到如何使用这种通用实现来编辑列表中的特定参数。
这段代码中的问号是什么意思?我应该什么时候使用它?我的代码在带或不带问号的情况下以相同的方式运行。
void dispose(){
bloc?.dispose();
super.dispose();
}
Run Code Online (Sandbox Code Playgroud) 我是Web开发的新手。为了安全起见,我将文件存储在不同的文件夹中时遇到问题。这是返回错误的索引页
<head>
<script src="../scripts/script.js"></script>
</head>
<body>
<?php include "../php/page.php"; ?>
Other code here...
</body>
Run Code Online (Sandbox Code Playgroud)
我的文件结构如下
www/
html/
index.php
scripts/
script.js
php/
page.php
Run Code Online (Sandbox Code Playgroud)
我不明白为什么包括php文件可以工作(提供的示例代码中的第5行)而包括javascript不起作用的原因(第2行)。我想您对此错误感兴趣,因此,这就是Google Chrome浏览器的控制台上显示的内容
Failed to load resource: the server responded with a status of 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
它还显示了该资源的链接,并且似乎在寻找my.server.address / scripts / script.js,就像它不在乎../部分一样。有人可以解释这种行为吗?