Я хочу сбросить значение в DropdownButtonFormField, значение изменяется на ноль, но DropdownButtonFormField не изменяется. В чем проблема? Если я использовал DropdownButton, это корректно изменяло значение, значение очищалось. Мне нужно использовать DropdownButtonFormField.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
String abc;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center (
child: Column(
children: <Widget>[DropdownButtonFormField(
hint: Text('select value'),
value: abc,
items: <String>['A', 'B', 'C', 'D'].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String newValue) {
setState(() {
abc = newValue;
});
},
),
Text("value is $abc"),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: (){
setState((){
abc = null;
});
},
tooltip: 'Reset',
child: Icon(Icons.clear),
)
),
);
}
}