我需要一些关于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;
});
},
),
),

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

对于问题1,您是否使用了不同的文本样式descriptionTextStyle & titleTextStyle

对于问题2,如果你想让可编辑文本只可用,只需添加bool,如果其他条件为

对于问题3,文本具有称为溢出的参数

您可以使用以下文本字段切换代码示例作为参考

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;
});
},
),
);
}
}

相关内容

  • 没有找到相关文章