Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 参数类型';字符串';can';不能分配给参数类型';UINT8列表';/颤振中的姿态法_Flutter_Dart - Fatal编程技术网

Flutter 参数类型';字符串';can';不能分配给参数类型';UINT8列表';/颤振中的姿态法

Flutter 参数类型';字符串';can';不能分配给参数类型';UINT8列表';/颤振中的姿态法,flutter,dart,Flutter,Dart,我已经试过了,但似乎无法通过这次考试。我试图使用颤振的姿态方法将一些变量发布到webView,但我不断地得到这个错误,我不确定我做错了什么。我还试着在网上找到一个使用这种方法的人的例子,但什么也找不到。有人请帮忙 page.dart: import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';

我已经试过了,但似乎无法通过这次考试。我试图使用颤振的姿态方法将一些变量发布到webView,但我不断地得到这个错误,我不确定我做错了什么。我还试着在网上找到一个使用这种方法的人的例子,但什么也找不到。有人请帮忙

page.dart:

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

Future main() async {
  runApp(new MyPaymentWidget());
}

class MyPaymentWidget extends StatefulWidget {
  RouteArgument routeArgument;
  MyPaymentWidget({Key key, this.routeArgument}) : super(key: key);
  @override
  _MyPaymentWidgetState createState() => new _MyPaymentWidgetState();
}

class _MyPaymentWidgetState extends State<MyPaymentWidget> {

  InAppWebViewController webView;
  String url = "";
  Uint8List postData;
  double progress = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        centerTitle: true, 
        title: Text(
          S.of(context).instant_eft_payment,
          style: Theme.of(context).textTheme.title.merge(TextStyle(letterSpacing: 1.3)),
        ),
      ),
        body: Container(
          child: Column(children: <Widget>[
            Container(
                padding: EdgeInsets.all(10.0),
                child: progress < 1.0
                    ? LinearProgressIndicator(value: progress)
                    : Container()),
            Expanded(
              child: Container(
                margin: const EdgeInsets.all(10.0),
                decoration:
                    BoxDecoration(border: Border.all(color: Colors.blueAccent)),
                child: InAppWebView(
                  initialUrl: "https://example.com/",
                  initialHeaders: {},
                  initialOptions: InAppWebViewWidgetOptions(
                    inAppWebViewOptions: InAppWebViewOptions(
                        debuggingEnabled: true,
                    )
                  ),
                  onWebViewCreated: (InAppWebViewController controller) {
                    webView = controller;
                    webView.postUrl(
                      url: 'https://example.com/', 
                      postData: "Amount=1&TransactionReference=some trans ref&BankReference=bank ref&Customer=thiscustomer&isTest=true");
                  },
                  onLoadStart: (InAppWebViewController controller, String url) {
                    setState(() {
                      this.url = url;
                    });
                  },
                  onLoadStop: (InAppWebViewController controller, String url) async {
                    setState(() {
                      this.url = url;
                    });
                  },
                  onProgressChanged: (InAppWebViewController controller, int progress) {
                    setState(() {
                      this.progress = progress / 100;
                    });
                  },
                ),
              ),
            ),
            ButtonBar(
              alignment: MainAxisAlignment.center,
              children: <Widget>[
                RaisedButton(
                  child: Icon(Icons.arrow_back),
                  onPressed: () {
                    if (webView != null) {
                      webView.goBack();
                    }
                  },
                ),
                RaisedButton(
                  child: Icon(Icons.arrow_forward),
                  onPressed: () {
                    if (webView != null) {
                      webView.goForward();
                    }
                  },
                ),
                RaisedButton(
                  child: Icon(Icons.refresh),
                  onPressed: () {
                    if (webView != null) {
                      webView.reload();
                    }
                  },
                ),
              ],
            ),
        ])),
      ),
    );
  }
}```

导入'dart:typed_data';
进口“包装:颤振/材料.省道”;
导入“包:flatter_inappwebview/flatter_inappwebview.dart”;
Future main()异步{
runApp(新的MyPaymentWidget());
}
类MyPaymentWidget扩展了StatefulWidget{
常规的常规的;
MyPaymentWidget({Key,this.routeArgument}):超级(Key:Key);
@凌驾
_MyPaymentWidgetState createState()=>new_MyPaymentWidgetState();
}
类_MyPaymentWidgetState扩展状态{
inappwebview控制器webView;
字符串url=“”;
UINT8列出postData;
双进度=0;
@凌驾
void initState(){
super.initState();
}
@凌驾
无效处置(){
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
appBar:appBar(
背景颜色:颜色。透明,
海拔:0,
标题:对,
标题:正文(
S.of(上下文)。即时付款,
样式:Theme.of(context).textTheme.title.merge(TextStyle(字母间距:1.3)),
),
),
主体:容器(
子项:列(子项:[
容器(
填充:所有边缘设置(10.0),
儿童:进步<1.0
?线性进度指示器(值:进度)
:Container()),
扩大(
子:容器(
边距:所有常数边集(10.0),
装饰:
BoxEdition(边框:border.all(颜色:Colors.blueAccent)),
子:InAppWebView(
初始URL:“https://example.com/",
initialHeaders:{},
initialOptions:InAppWebViewWidgetOptions(
inappwebview选项:inappwebview选项(
debuggingEnabled:true,
)
),
onWebViewCreated:(InAppWebViewController){
网络视图=控制器;
webView.postrl(
网址:'https://example.com/', 
postData:“金额=1,交易参考=某些交易参考&银行参考=银行参考&客户=此客户&isTest=真”);
},
onLoadStart:(InAppWebViewController控制器,字符串url){
设置状态(){
this.url=url;
});
},
onLoadStop:(InAppWebViewController控制器,字符串url)异步{
设置状态(){
this.url=url;
});
},
onProgressChanged:(InAppWebViewController控制器,int进度){
设置状态(){
这个。进度=进度/100;
});
},
),
),
),
钮扣杆(
对齐:MainAxisAlignment.center,
儿童:[
升起的按钮(
子:图标(图标。箭头返回),
已按下:(){
if(webView!=null){
webView.goBack();
}
},
),
升起的按钮(
子:图标(图标。向前箭头),
已按下:(){
if(webView!=null){
webView.goForward();
}
},
),
升起的按钮(
子:图标(Icons.refresh),
已按下:(){
if(webView!=null){
reload();
}
},
),
],
),
])),
),
);
}
}```

postData的
postrl
参数是一个
Uint8List
,但是您正在传递一个
字符串。我假设这应该是字符串的
codeUnits
(UTF-16表示)或UTF-8编码

尝试将其中一个作为
postData
参数传递:

Uint8List.fromList(myPostData.codeUnits);

//这需要dart:convert
Uint8List.fromList(utf8.encode(myPostData));

codeUnits
是字符串的UTF-16编码。OP需要
utf8.encode
选项。多亏了你们两位,使用了utf8选项,错误消失了。我成功地进行了一次测试。还有一个问题:utf8编码是否会更改字符串上的值?我这样问是因为“myPostData”实际上是一个串接了一个散列值的字符串。当我进行utf编码时,哈希检查失败。@DotComLabZA Dart使用utf-16在内部表示字符串。当您将其转换为UTF-8时,它是一个不同的值,因此使用不同的哈希代码是有意义的。(还有一个事实是,您正在生成
Uint8List
的哈希代码,而不是
字符串的哈希代码,后者可能具有完全不同的哈希代码计算实现。)只要原始字符串不包含UTF-8不直接支持的任何字符,您应该能够使用
utf8轻松地将其转换回本机省道字符串。解码
@Abion47上述解释确实有助于我理解发生了什么,谢谢。然而,我正在努力应用它。我的说话人