我可以制作一个Counter应用。 我可以导航到新屏幕。
我要的是,在主视图中创建一个计数器,然后单击设置按钮。内部设置按钮->更改屏幕视图以及要计数的计数器大小。并计算大小。那是不可能的,还是有bug的?
但是我不能同时做到:(
这是我的代码,我可以更改视图,但是我不能更改文本。
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!'),
),
),
);
}
}
有人可以帮我吗?
谢谢:)