Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

flutter - Convert text widget to text field widget on particular text click

If user clicks on particular text it should be converted to text field and i need to get the input value from the user, so far i have added string into list using split and showing the list items using listview.

i have two doubts. 1.how can i convert text into textfield on particular text click. 2.if i retrun textfield in listview it takes full width, i could't wrap textfield inside container by giving width, since text width might change based on API response

any suggestion would be appreciated.

this is what i need to achieve

  String demoString = 'You might want to try eating more healthy food.';

  new Row(children: <Widget>[
              Expanded(
                  child: SizedBox(
                      height: 150.0,
                      child: ListView(
                        padding: EdgeInsets.all(20),
                        scrollDirection: Axis.horizontal,
                        children: demoString
                            .split(' ')
                            .map((String text) => Padding(
                                padding: const EdgeInsets.all(18.0),
                                child: Text(text)))
                            .toList(),
                      )))
            ])

question from:https://stackoverflow.com/questions/65887856/convert-text-widget-to-text-field-widget-on-particular-text-click

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To be able to click and get a textfield you should create a little widget (for example) which will detect if he receive a click (gestureDetector / inkWell ...) and then change a widget by an other one.

For example, MySwapWidget will contain this idea :

MySwapWidget(
  selected: (default value, could be useful, false by default) true / false,
  childIfSelected: TextField(),
  childIfNotSelected: Text(),
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...