flutter - 颤振 - 不能让两者同时工作
问题描述
我可以制作一个计数器应用程序。我可以导航到新屏幕。
我想要的是,在主视图和设置按钮中创建一个计数器。内部设置按钮 -> 更改屏幕视图和计数的计数器大小。并计算大小。这是不可能的,还是在错误?
但我不能同时做到:(
这是我的代码,我可以更改视图,但无法更改文本。
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Named Routes Demo',
// Start the app with the "/" named route. In this case, the app starts
// on the FirstScreen widget.
initialRoute: '/',
routes: {
// When navigating to the "/" route, build the FirstScreen widget.
'/': (context) => FirstScreen(),
// When navigating to the "/second" route, build the SecondScreen widget.
'/second': (context) => SecondScreen(),
},
));
}
class FirstScreen extends StatelessWidget {
String changetext = 'Change me !';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Screen'),
),
body: Center(
child: Container(
child: Column(
children: <Widget>[
Text(changetext),
RaisedButton(
child: Text('Press Me To update Text !'),
onPressed: (){
changetext = 'it has been changed';
},
),
RaisedButton(
child: Text('Change View'),
onPressed: (){
Navigator.pushNamed(context, '/second');
},
)
],
),
),
),
);
}
}
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Screen"),
),
body: Center(
child: RaisedButton(
onPressed: () {
// Navigate back to the first screen by popping the current route
// off the stack.
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
}
有人可以帮我吗?
谢谢 :)
解决方案
推荐阅读
- ldap - 多个地点和部门的 LDAP 过滤器查询
- typescript - 该函数应返回一个对象,该对象具有 key 作为参数 someKey 和 value 作为 someValue
- python - 如何在python中堆叠2个不同长度的numpy数组
- html - 如何制作(最)基本的 .htaccess 文件来密码保护网站
- java - 如何在 RecyclerView 中选择单个项目?
- google-sheets - 根据左侧单元格的条件对单元格求和
- android - Open fragment from another one in kotlin
- c# - How to redirect after certain path ASP.NET MVC 5
- python - 如何从外部判断一个进程有多少个 python 线程?
- flutter - 在颤振中调用函数时出现字符串子类型错误