【问题标题】:How could i make my qrCode image responsive in flutter我怎样才能让我的 qrCode 图像响应颤动
【发布时间】:2020-12-13 19:49:46
【问题描述】:

我正在尝试制作一个 qrCode 生成器,但由于页面太大,我无法正确完成。有人可以帮我吗?................................................ ..................................................... ..................................................... ..................................................... ..........

import 'package:flutter/material.dart';
import 'package:parse_server_sdk_flutter/parse_server_sdk.dart';
import 'package:qr_flutter/qr_flutter.dart';

class Generate extends StatefulWidget {
  @override
  _GenerateState createState() => _GenerateState();
}

class _GenerateState extends State<Generate> {
  String qrData = "SHS HTW App";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('QrCode Generate'),
      ),
      body: Container(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Container(
                child: Padding(
                  padding: const EdgeInsets.fromLTRB(80, 10, 10, 180),
                  child: QrImage(
                    //place where the qr image will be shown
                    data: qrData,
                    size: 200,
                  ),
                ),
              ),
              SizedBox(
                height: 40.0,
              ),
              Text("get your data/ linked to the QR Code"),
              TextField(
                //place where we enter the text od data
                controller: qrText,
                decoration: InputDecoration(
                  hintText: "Enter the data/Link",
                ),
              ),
              Padding(
                padding: const EdgeInsets.fromLTRB(40, 20, 40, 0),
                child: FlatButton(
                  padding: EdgeInsets.all(15.0),
                  child: Text("generate qr code"),
                  //what should ahppen when we press the button
                  onPressed: () {
                    if (qrText.text.isEmpty) {
                      setState(() {
                        qrData = "";
                      });
                    } else {
                      qrData = qrText.text;
                    }
                  },
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(20.0),
                      side: BorderSide(color: Colors.green, width: 3.0)),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  final qrText = TextEditingController();
}

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    我认为您正在尝试使内容适合屏幕。您可以使用 SafeArea 类,以便您可以将内容从左、右、上或下对齐到屏幕。但我认为你必须先阅读帖子规则! Safearea class here

    【讨论】:

    • 它对我不起作用。但我通过用 Expanded 包装我的子小部件找到了解决方案。它工作得很好。不过谢谢
    猜你喜欢
    • 1970-01-01
    • 2013-08-25
    • 2020-06-22
    • 2021-11-25
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    相关资源
    最近更新 更多