I am trying change the text on the click of the button using flutter.
I have splited the widgets to different dart files. I want to add text from the different dart file but getting error as "Positional arguments must occur before named arguments. while passing the value to the constructor named TextOutput.
What does this error mean? a beginner in flutter so explanation of this error will be a great help.
I am trying to pass value to the contructor but getting this error.
class TextControlState extends State<TextControl> {
String _mainText="Hey Divya Here!";
void _changeText() {
setState(() {
this._mainText = "This changed!";
});
}
Widget build(BuildContext context) {
return Center(
child: Container(
margin: EdgeInsets.all(8),
child:
RaisedButton(
child:
Text('Change Text', style: TextStyle(color: Colors.white, fontSize: 18)),
onPressed: _changeText,
),
TextOutput(_mainText)
),
);
TextOutput dart file
import 'package:flutter/material.dart';
class TextOutput extends StatelessWidget {
final String mainText;
TextOutput(this.mainText);
@override
Widget build(BuildContext context) {
return Text(mainText);
}
}
The value of the text should be changed on clicking of the button.
TextOutput
widget into theContainer
, but it already has achild
- theRaisedButton
. Do you want the button and output to both appear inside the container? If so, put aColumn
in the container and add the other two widgets to that. As it stands, this has nothing to do with moving the second widget to its own source file. – Richard Heap