只是测试颤振。下面的代码示例是一个非常简单的 flutter 应用程序。问题是我不知道如何在 TestTextState 类中调用 setState() 函数,以便在每次按下更改按钮时更改文本。
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Test app',
home: new Scaffold(
appBar: new AppBar(
title: new Text("Test"),
),
body: new Test(),
),
);
}
}
class Test extends StatelessWidget {
final TestText testText = new TestText();
void change() {
testText.text == "original" ? testText.set("changed") : testText.set("original");
}
@override
Widget …
Run Code Online (Sandbox Code Playgroud)