I am totally flutter beginner.
What I want to do is pass the data (by TextController) from StatefulWidget to another one.
Here is my code (passive Widget)
import 'package:flutter/material.dart';
class VocabularyText extends StatefulWidget {
final String text;
// ignore: sort_constructors_first
const VocabularyText ({ Key key, this.text }): super(key: key);
@override
_VocabularyTextState createState() => _VocabularyTextState();
}
class _VocabularyTextState extends State<VocabularyText> {
Offset offset = Offset.zero;
@override
Widget build(BuildContext context) {
return Container(
child: Positioned(
left: offset.dx,
top: offset.dy,
child: GestureDetector(
onPanUpdate: (details) {
setState(() {
offset = Offset(
offset.dx + details.delta.dx, offset.dy + details.delta.dy);
});
},
child: const SizedBox(
width: 300,
height: 300,
child: Padding(
padding: EdgeInsets.all(8),
child: Center(
child: Text(
'a',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 28,
color: Colors.red
)
),
),
),
)),
),
);
}
}
The thing is here
child: Text(
//
widget.text,
//
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 28,
color: Colors.red
)
),
According to my research, this should work, but it doesn't. Why did I make a mistake?
Here is references
- How to add a draggable "textfield" to add text over images in flutter?
- Passing Data to a Stateful Widget
Thank you in advance.