Home > Back-end >  I need some input regarding the Texteditingcontroller and overflowing pixels
I need some input regarding the Texteditingcontroller and overflowing pixels

Time:07-04

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;

                    });
                  },

                ),
              ),


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

CodePudding user response:

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

CodePudding user response:

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

  • Related