Reputation:
I found online that underscore fields, classes and methods will only be available in the .dart file where they are defined but it seems that my code goes against it:
Code sinppet from main.dart:
class _TestState extends State<Test> {
int a = 0;
void increase() {
setState(() {
a = a + 1;
});
}
var b = ['hello', 'bye'];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
children: <Widget>[Text(b[a]), MyButton(increase)],
)),
);
}
}
Code snippet from MyButton.dart:
class MyButton extends StatelessWidget {
final Function x;
MyButton(this.x);
@override
Widget build(BuildContext context) {
return Container(
child: RaisedButton(onPressed: x,child:Text('press me')),
);
}
}
How is MyButton able to call a method from _TestState when it exists in a different file.
Upvotes: 0
Views: 1476