我需要一些有关texteditingController和溢出像素的输入
我有几个有关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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于问题编号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
您可以将以下TextField切换代码示例用作参考。
you can use the following textfield toggle code sample as a ref.