Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.dart file:
- import 'package:flutter/material.dart';
- import 'dropDowns.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: MyHomePage(),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- MyHomePage({Key key}) : super(key: key);
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: PreferredSize(
- child: Text("my app"),
- preferredSize: Size.fromHeight(55.0),
- ),
- body: Container(
- width: MediaQuery.of(context).size.width,
- child: SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- DropDown(),
- Button(),
- // Row(
- // mainAxisAlignment: MainAxisAlignment.spaceBetween,
- // children: <Widget>[
- // // Expanded(child: VahaPilota()),
- // SizedBox(
- // width: MediaQuery.of(context).size.width * 0.1,
- // ),
- // // DeleteBtn(),
- // ],
- // ),
- // TextVahy(visibility: false),
- ],
- ),
- ),
- ),
- );
- }
- }
- DropDown.dart file:
- import 'package:flutter/material.dart';
- class DropDown extends StatefulWidget {
- @override
- DropDownState createState() => DropDownState();
- }
- class DropDownState extends State<DropDown> {
- List<String> _myList = ["Item 1", "Item 2", "Item 3", "Item 4"];
- var currentItemSelected = "Item 1";
- @override
- Widget build(BuildContext context) {
- return Center(
- child: Container(
- color: Colors.blue,
- child: ButtonTheme(
- child: DropdownButton<String>(
- dropdownColor: Colors.blue,
- items: _myList.map((String dropDownStringItem) {
- return DropdownMenuItem<String>(
- value: dropDownStringItem,
- child: Text(
- dropDownStringItem,
- ),
- );
- }).toList(),
- onChanged: (String newItemSelected) {
- setState(() {
- currentItemSelected = newItemSelected;
- Button(myText: newItemSelected);
- });
- },
- value: currentItemSelected,
- ),
- ),
- ),
- );
- }
- }
- class Button extends StatefulWidget {
- final String myText;
- Button({this.myText});
- @override
- ButtonState createState() => ButtonState();
- }
- class ButtonState extends State<Button> {
- @override
- Widget build(BuildContext context) {
- return Center(
- child: Column(
- children: <Widget>[
- RaisedButton(
- child: Text("Button"),
- onPressed: () {
- // it should update my 'myText' in Text widget below
- },
- ),
- Text(widget.myText == null ? "Default text" : widget.myText),
- ],
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement