gpt4 book ai didi

list - 将列表传递给 QR 生成器

转载 作者:IT王子 更新时间:2023-10-29 07:04:07 25 4
gpt4 key购买 nike

我是 Flutter 编程的新手,我正在尝试创建一个披萨应用程序。首先你制作披萨,选择配料,然后你会得到一份订单 list 。该列表和 qr 生成器也有效,但它们来自单独的教程,我在连接它们时遇到问题。我似乎无法将订单列表传递给生成器。

import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'dart:typed_data';
import 'dart:ui';
import 'dart:io';
import 'package:flutter/rendering.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pizza_app/screens/review.dart';
import 'package:pizza_app/code/pizza.dart';

class GenerateQR extends StatefulWidget {
List<String> _list = new List<String>();
@override
State<StatefulWidget> createState() => GenerateQRState();

GenerateQR(list){

_list = list;
}

}

class GenerateQRState extends State<GenerateQR> {

static const double _topSectionTopPadding = 50.0;
static const double _topSectionBottomPadding = 20.0;
static const double _topSectionHeight = 50.0;

GlobalKey globalKey = new GlobalKey();
List<String> _dataList = new List<String>();
//String _dataString = "Hello from this QR";
String _inputErrorText;
final TextEditingController _textController = TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('QR Code Generator'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.share),
onPressed: _captureAndSharePng,
)
],
),
body: _contentWidget(),
);
}

Future<void> _captureAndSharePng() async {
try {
RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
var image = await boundary.toImage();
ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();

final tempDir = await getTemporaryDirectory();
final file = await new File('${tempDir.path}/image.png').create();
await file.writeAsBytes(pngBytes);

final channel = const MethodChannel('channel:me.alfian.share/share');
channel.invokeMethod('shareFile', 'image.png');

} catch(e) {
print(e.toString());
}
}

_contentWidget() {
final bodyHeight = MediaQuery.of(context).size.height - MediaQuery.of(context).viewInsets.bottom;
return Container(
color: const Color(0xFFFFFFFF),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
top: _topSectionTopPadding,
left: 20.0,
right: 10.0,
bottom: _topSectionBottomPadding,
),
child: Container(
height: _topSectionHeight,
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: TextField(
controller: _textController,
decoration: InputDecoration(
hintText: "Enter a custom message",
errorText: _inputErrorText,
),
),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: FlatButton(
child: Text("SUBMIT"),
onPressed: () {
setState((){

_dataList.add(_list); // This must be wrong
_inputErrorText = null;
});
},
),
)
],
),
),
),
Expanded(
child: Center(
child: RepaintBoundary(
key: globalKey,
child: QrImage(
data: _dataList,// I think that there is an error here too
size: 0.5 * bodyHeight,
onError: (ex) {
print("[QR] ERROR - $ex");
setState((){
_inputErrorText = "Error! Maybe your input value is too long?";
});
},
),
),
),
),
],
),
);
}
}

最佳答案

使用Iterable.Join()使用合适的分隔符(如竖线 (|) 符号)将您的字符串列表连接成一个字符串:

处理有人在 TextField 中键入 | 字符的情况。

读取二维码的代码可以使用String.split()将字符串再次拆分为字符串列表。

关于list - 将列表传递给 QR 生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55110172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com