gpt4 book ai didi

widget - 如何使用子部件更改 AppBar 内容?

转载 作者:IT王子 更新时间:2023-10-29 07:00:52 26 4
gpt4 key购买 nike

我正在尝试将 AppBar 标题从 LoginWidget 级别更改为“登录”,但我不知道该怎么做。

它可能看起来像 IoC 模式,但我认为它仍然可以做到。

我现在正在尝试扩展一个 Scaffold 对象并向其添加一些方法,但它似乎不起作用。

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(
home: new Scaffold(
appBar: new AppBar(
backgroundColor: Colors.amber,
title: new Text("Application name")
),
body: new LoginWidget()
)
);
}
}

最佳答案

这是不可能的

小部件不能以任何方式修改其他小部件。他们唯一能做的就是提交事件,让他们可能使用react。

只有 MyApp 可以更改应用栏。

关于widget - 如何使用子部件更改 AppBar 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50777546/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com