有人知道我该怎么做吗?
我的代码:
@override
void dispose() {
final FiltersBloc filtersBloc =
BlocProvider.of<FiltersBloc>(context);
super.dispose();
}
Run Code Online (Sandbox Code Playgroud)
错误是:
flutter: BlocProvider.of() called with a context that does not contain a Bloc of type FiltersBloc.
flutter: No ancestor could be found starting from the context that was passed to
flutter: BlocProvider.of<FiltersBloc>().
flutter:
flutter: This can happen if:
flutter: 1. The context you used comes from a widget above the BlocProvider.
flutter: 2. You used MultiBlocProvider and didn't explicity provide the BlocProvider types.
flutter:
flutter: Good: BlocProvider<FiltersBloc>(builder: …Run Code Online (Sandbox Code Playgroud) 我正在使用 AnimatedOpacity 来隐藏基于滚动事件的导航栏。我特别无法让它很好地进出动画,同时也使小部件不可点击。
为了隐藏我的小部件并防止它被点击,我有条件地渲染我的CustomNavBar()组件或Container()基于可见状态。但是,当我淡出时,这会突然切断我的动画。然而,它会逐渐消失。
AnimatedOpacity(
opacity: _isVisible ? 1.0 : 0.0,
duration: Duration(milliseconds: 300),
child: _isVisible
? CustomNavBar()
: Container(),
)
Run Code Online (Sandbox Code Playgroud)
这是意料之中的,因为当 _isVisible 为 false 时,组件实际上不存在。这杀死了整个动画。我该如何解决这个问题?
谢谢
I am using react hooks and useRef to call a child method from the parent (see here: Call child method from parent)
Specifically, I am trying to call the formik submitForm method which is located in my child component from my parent component. I know there are other ways to do this (React Formik use submitForm outside <Formik />) but i would really like to use useRef.
const Auth1 = forwardRef((props, ref) => {
useImperativeHandle(ref, () => …Run Code Online (Sandbox Code Playgroud) 我试图在飞镖正则表达式中捕获符号。我的正则表达式如下所示:
RegExp containsSymbolRegExp = RegExp(r"[-!$%^&*()_+|~=`{}\[\]:;'<>?,.\/]");
Run Code Online (Sandbox Code Playgroud)
但是,我还需要让它抓住符号“我不能粘在那里”,因为它与字符串混淆。任何想法如何做到这一点?谢谢。
编辑:jamesdlin 的回答非常适合飞镖。但它不适用于我的颤振应用程序,所以我认为它与颤振有关。这是我将其应用于的代码:
TextEditingController _passwordController = TextEditingController();
bool containsSymbol;
RegExp containsSymbolRegExp = RegExp(r"[-!$%^&*()_+|~=`{}#@\[\]:;'<>?,.\/"
'"'
"]");
void _handleChange(text) {
setState(() {
containsSymbol = containsSymbolRegExp.hasMatch(_passwordController.text);
});
print(containsSymbol); // always prints false for " ' \ but works for all other symbols
}
Widget _textField(controller, labelText) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(labelText, style: TextStyle(fontSize: 11)),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: 35,
child: TextField(
onChanged: _handleChange,
style: TextStyle(fontSize: 20),
keyboardType: TextInputType.text,
controller: _passwordController,
cursorColor: Colors.grey,
decoration: …Run Code Online (Sandbox Code Playgroud) 我想在 dart 中使用 http GET 请求发送参数。这里的第一个答案很好地展示了它:如何向 Dart http 请求添加查询参数?
var uri =
Uri.https('www.myurl.com', '/api/query', queryParameters);
Run Code Online (Sandbox Code Playgroud)
然而,一个主要的问题是 queryParameters 只接受:
Map<String, String>
Run Code Online (Sandbox Code Playgroud)
这不允许我传入列表/数组。
如果我将 get 请求更改为 post 请求,我可以轻松地发送一个正文(作为 json 编码的字符串),如 flutter 文档所述:https : //pub.dev/documentation/http/latest/http/post .html
post(url, {Map<String, String> headers, body, Encoding encoding})
Run Code Online (Sandbox Code Playgroud)
但是,get 请求对于查询参数没有这样的等效参数:https : //pub.dev/documentation/http/latest/http/get.html
get(url, {Map<String, String> headers})
Run Code Online (Sandbox Code Playgroud)
我还尝试将查询参数直接添加到 url 中,如下所示:
get('www.myurl.com/api/query/?array[]=value1&array[]=value2&array[]=value3)
Run Code Online (Sandbox Code Playgroud)
但是当我在服务器中收到方括号 [] 时,它总是会转换为 %5B%5D 。
任何帮助表示赞赏。谢谢
我将 socket.io 用于多个聊天室,并希望我的套接字连接仅在聊天室打开时存在,并在聊天室卸载时关闭。目前,我连接到 useEffect 挂钩中的套接字。问题是,我无法在任何函数中执行 socket.emit() ,因为我的套接字是在 useEffect 中定义的,如下所示:
import io from 'socket.io-client'
export default function Chat() {
useEffect(() => {
const socket = io(endpoint + '/chat')
return () => { socket.disconnect() }
}
const sendMessage = (msg) => {
// Cant access this because socket is defined in useEffect!
socket.emit('message', msg)
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在导入下声明我的套接字,如下所示:
import io from 'socket.io-client'
const socket = io(endpoint + '/chat')
export default function Chat() {
...
}
Run Code Online (Sandbox Code Playgroud)
然而,这种方式的问题是
socket.disconnect()
useEffect 钩子内部不再起作用,并且套接字连接保持活动状态。
我还尝试将套接字声明为函数的变量,如下所示:
export default function …Run Code Online (Sandbox Code Playgroud) 我的 connectTimeout 和 receiveTimeouts 不起作用。这是我的代码:
BaseOptions options = new BaseOptions(
baseUrl:
'http://localhost:5000/api',
connectTimeout: 5000,
receiveTimeout: 3000,
responseType: ResponseType.plain);
Dio myDio = new Dio(options);
// api file
final response = await myDio.get('/test');
// on the backend in Node.js, i delay my response with:
setTimeout(function () { res.status(201).json(result) }, 50000)
Run Code Online (Sandbox Code Playgroud)
然而,这是行不通的。然而有趣的是,如果我这样做它就会起作用:
myDio.options.connectTimeout = 5000;
myDio.options.receiveTimeout = 3000;
final response = await myDio.get('/test');
Run Code Online (Sandbox Code Playgroud)
我真的不想这样做,因为我有很多 api 调用,并且我希望我的myDio实例能够处理所有超时。知道如何解决这个问题,或者发生了什么事吗?
谢谢
我有一个带有多个容器和 blob 的天蓝色存储帐户:
container1 -> blob1.txt, blob2.jpg
container2 -> blob1.png
container3 ->
Run Code Online (Sandbox Code Playgroud)
我想生成一个只能从container1读取和写入的 SAS 。
第一个问题:我应该使用generateAccountSASQueryParameters还是generateBlobSASQueryParameters来执行此操作?
第二个问题:我一直在尝试使用generateBlobSASQueryParameters 来实现这一点。但是,我不断收到此错误:
<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is
formed correctly including the signature. RequestId:1db4c573-201e-0083-2396-ab3df5000000
Time:2019-12-05T18:05:52.8934222Z
</Message>
<AuthenticationErrorDetail>
The specified signed resource is not allowed for the this resource level
</AuthenticationErrorDetail>
</Error>
Run Code Online (Sandbox Code Playgroud)
我用来执行此操作的代码在这里:
const account = "storageaccountname";
const accountKey = "<myKey>";
const sharedKeyCredential = new AzureStorageBlob.StorageSharedKeyCredential(account, accountKey);
const blobServiceClient = new AzureStorageBlob.BlobServiceClient( …Run Code Online (Sandbox Code Playgroud)