import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyValueChanger extends StatelessWidget {
final ValueChanged<String> onValueChanged;
const MyValueChanger({this.onValueChanged});
@override
Widget build(BuildContext context) {
return RaisedButton(
child: Text('Press me'),
onPressed: () => this.onValueChanged('NEW VALUE'));
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: MyValueChanger(
onValueChanged: (value) => print('Value changed to: $value')),
),
),
);
}
}