import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: "Sateful App Exampl",
home: FavoriteCity(),
)
);
}
//----------------------------------------------------------
class FavoriteCity extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return _FavoriteCityState();
}
}
//---------------------------------------------------------
class _FavoriteCityState extends State<FavoriteCity>{
String nameCity = "";
var _currencies = ['Rupess','Dollar','Pound','other'];
var _currentItemSelected = 'Rupees';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Stateful App Example"),
),
body: Container(
color: Colors.lightBlueAccent,
margin: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
TextField(
onSubmitted: (String userInput){
setState(() {
nameCity = userInput;
});
},
),
DropdownButton<String>(
items: _currencies.map((String dropDownStringItem){
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(dropDownStringItem),
);
}).toList(),
onChanged: (String newValueSelected){
//your code to execute , when a menu item is selected from drop down
_onDropDownItemSelected(newValueSelected);
},
value: _currentItemSelected,
),
Padding(
padding: EdgeInsets.all(30.0),
child: Text(
"Your Text City Is :- $nameCity",
style: TextStyle(fontSize: 20.0,backgroundColor: Colors.yellow),
))
],
),
),
);
}
void _onDropDownItemSelected(String newValueSelected){
setState(() {
this._currentItemSelected = newValueSelected;
});
}
}
0 Comments
Post a Comment