Html 当值发生变化时,如何呈现文本?

Html 当值发生变化时,如何呈现文本?,html,flutter,dart,text,render,Html,Flutter,Dart,Text,Render,我有下面简单的代码 SingleChildScrollView( child: RichText( overflow: TextOverflow.clip, text: TextSpan( text: '${model.logMain.text}', style: DefaultTextStyle.of(context).style, children: <TextSpan>[ Text

我有下面简单的代码

SingleChildScrollView(
   child: RichText(
      overflow: TextOverflow.clip,
      text: TextSpan(
        text: '${model.logMain.text}',
        style: DefaultTextStyle.of(context).style,
        children: <TextSpan>[
          TextSpan(
              text: '${model.value.text}',
              style: TextStyle(
                  color: Colors.blue,
                  fontWeight: FontWeight.bold)),
        ],
      ),
    ),
),
SingleChildScrollView(
孩子:RichText(
溢出:TextOverflow.clip,
text:TextSpan(
text:“${model.logMain.text}”,
样式:DefaultTextStyle.of(context.style),
儿童:[
TextSpan(
text:“${model.value.text}”,
样式:TextStyle(
颜色:颜色,蓝色,
fontWeight:fontWeight.bold),
],
),
),
),

如何在变量model.value.text更改时添加(更多)文本,请帮助我

只需复制并通过我的源代码即可:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Render text after change input',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController inputController = TextEditingController();
  var giveInput="";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Render text after change input'),
        centerTitle: true,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child:Column(
          children: [
       Column(
         children: <Widget>[
           Center(
             child: Container(
                 width: MediaQuery.of(context).size.width * 0.8,
                 height: 40,
                 child: TextField(
                   textAlign: TextAlign.center,
                   textAlignVertical: TextAlignVertical.bottom,
                   // controller: passwordController..text="omor06799",
                   decoration: InputDecoration(
                     border: OutlineInputBorder(),
                     labelText: 'Enter Input',
                     hintText: 'type input here',
                   ),
                   autofocus: true,
                   onChanged: (text) {
                     setState(() {
                       giveInput=text;
                       print("First text field: $text");
                     });

                   },
                 )),
           ),
           Container(
             padding: EdgeInsets.all(10),
           ),
           giveInput==null?Text("Your type input is :"):Text("your type input is : "+giveInput),

         ],
       )
          ],
        )

      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“更改输入后呈现文本”,
主题:主题数据(
主样本:颜色。蓝色,
),
主页:MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
TextEditingController输入控制器=TextEditingController();
var输入=”;
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“更改输入后呈现文本”),
标题:对,
),
主体:填充物(
填充:常数边集全部(16.0),
子:列(
儿童:[
纵队(
儿童:[
居中(
子:容器(
宽度:MediaQuery.of(context).size.width*0.8,
身高:40,
孩子:TextField(
textAlign:textAlign.center,
textAlignVertical:textAlignVertical.bottom,
//控制器:passwordController..text=“omor06799”,
装饰:输入装饰(
边框:OutlineInputBorder(),
labelText:“输入”,
hintText:'在此处键入输入',
),
自动对焦:对,
一旦更改:(文本){
设置状态(){
输入=文本;
打印(“第一个文本字段:$text”);
});
},
)),
),
容器(
填充:边缘设置。全部(10),
),
giveInput==null?Text(“您的类型输入为:”):Text(“您的类型输入为:”+giveInput),
],
)
],
)
),
);
}
}

当您更改数据值并希望UI知道它时,它将100%工作。

只需调用

          setState(() {
                   value= "some new value";
                 });

将其作为变量放在setState()上,然后它将更新,如输出:texta。。。。。值更改时:texta。。。。。。这能回答你的问题吗?我想呈现(添加)文本时,值变化statefull小部件,阅读更多关于状态管理,你可以使用GetX它将是最简单的方法来做这件事