我需要一些有关texteditingController和溢出像素的输入

发布于 2025-02-13 07:12:30 字数 2875 浏览 3 评论 0原文

我有几个有关TextEditingController的问题。我终于设法使文本可以编辑,但是它并没有返回我最初用于文本的字体/大小。我也试图禁用编辑文本,但它不起作用。我希望最终某些用户可以访问可编辑的文本,这是否有可能?同样,当我在Chrome上显示文本时,它会显示一些溢出的像素,我想知道可能是什么原因。

import 'package:bestfitnesstrackereu/widgets/page_content_details/informations_content_details.dart';
import 'package:flutter/material.dart';
import 'package:responsive_builder/responsive_builder.dart';
import '../../constants/text_styles.dart';

class InformationContentDetails extends StatefulWidget {
  const InformationContentDetails({Key key}) : super(key: key);

  @override

  State<InformationContentDetails> createState() => _InformationContentDetails();
}
class _InformationContentDetails extends State<InformationContentDetails> {
  final _controller = TextEditingController();
  final _controller2 = TextEditingController();

  String name = " Informationen";
  String name2 = "Welcome here";


  @override
  Widget build(BuildContext context) {
    return ResponsiveBuilder(
      builder: (context, sizingInformation) {
        var textAlignment;
        if (sizingInformation.deviceScreenType == DeviceScreenType.desktop) {
          textAlignment = TextAlign.left;
        } else {
          textAlignment = TextAlign.center;
        }

        return Container(
          width: 650,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                name,
                style: titleTextStyle(sizingInformation.deviceScreenType),
                textAlign: textAlignment,
              ),
              Container(
                child: TextField(
                  enabled: false,
                  controller : _controller,
                ),
              ),
              Container(
                child: FlatButton(
                  child: Text('edit'),
                  onPressed:(){
                    setState((){
                      name = _controller.text;


                    });
                  },

                ),
              ),
              SizedBox(
                height: 30,
              ),
              Text(
                name2,
                style: descriptionTextStyle(sizingInformation.deviceScreenType),
                textAlign: textAlignment,
              ),
              Container(
                child: TextField(
                  controller : _controller2,
                ),
              ),
              Container(
                child: FlatButton(
                  child: Text('edit'),
                  onPressed:(){
                    setState((){
                      name2 = _controller2.text;

                    });
                  },

                ),
              ),


            ],
          ),
        );
      },
    );
  }
}

I have a few questions regarding the Texteditingcontroller. I finally managed to make my text editable, but it doesnt return the font/size i initially used for my text. Also i tried to disable the edit Text but it doesn´t work. I want the editable Text only to be accessible to certain users in the end, is there a possibility for this? Also when i display the Text on Chrome it shows some overflowing Pixels, i would like to know what the cause for this could be.

import 'package:bestfitnesstrackereu/widgets/page_content_details/informations_content_details.dart';
import 'package:flutter/material.dart';
import 'package:responsive_builder/responsive_builder.dart';
import '../../constants/text_styles.dart';

class InformationContentDetails extends StatefulWidget {
  const InformationContentDetails({Key key}) : super(key: key);

  @override

  State<InformationContentDetails> createState() => _InformationContentDetails();
}
class _InformationContentDetails extends State<InformationContentDetails> {
  final _controller = TextEditingController();
  final _controller2 = TextEditingController();

  String name = " Informationen";
  String name2 = "Welcome here";


  @override
  Widget build(BuildContext context) {
    return ResponsiveBuilder(
      builder: (context, sizingInformation) {
        var textAlignment;
        if (sizingInformation.deviceScreenType == DeviceScreenType.desktop) {
          textAlignment = TextAlign.left;
        } else {
          textAlignment = TextAlign.center;
        }

        return Container(
          width: 650,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                name,
                style: titleTextStyle(sizingInformation.deviceScreenType),
                textAlign: textAlignment,
              ),
              Container(
                child: TextField(
                  enabled: false,
                  controller : _controller,
                ),
              ),
              Container(
                child: FlatButton(
                  child: Text('edit'),
                  onPressed:(){
                    setState((){
                      name = _controller.text;


                    });
                  },

                ),
              ),
              SizedBox(
                height: 30,
              ),
              Text(
                name2,
                style: descriptionTextStyle(sizingInformation.deviceScreenType),
                textAlign: textAlignment,
              ),
              Container(
                child: TextField(
                  controller : _controller2,
                ),
              ),
              Container(
                child: FlatButton(
                  child: Text('edit'),
                  onPressed:(){
                    setState((){
                      name2 = _controller2.text;

                    });
                  },

                ),
              ),


            ],
          ),
        );
      },
    );
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南薇 2025-02-20 07:12:30

对于问题编号1,您不是使用不同的文本样式description textstyle&amp; titletextStyle

问题编号

2

For question no.1 aren't you using different text style descriptionTextStyle & titleTextStyle

For question no.2 if you want to make the editable text only availble person just add bool and if else condition

For question no.3 Text have params called overflow

錯遇了你 2025-02-20 07:12:30

您可以将以下TextField切换代码示例用作参考。

class MyWidget extends StatefulWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  bool isEnable = false;
  final TextEditingController _controller = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: TextField(
        controller: _controller,
        enabled: isEnable,
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            isEnable = !isEnable;
          });
        },
      ),
    );
  }
}

you can use the following textfield toggle code sample as a ref.

class MyWidget extends StatefulWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  bool isEnable = false;
  final TextEditingController _controller = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: TextField(
        controller: _controller,
        enabled: isEnable,
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            isEnable = !isEnable;
          });
        },
      ),
    );
  }
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文