Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.24 KB | None | 0 0
  1. main.dart file:
  2.  
  3.  
  4.  
  5. import 'package:flutter/material.dart';
  6. import 'dropDowns.dart';
  7.  
  8. void main() {
  9.   runApp(MyApp());
  10. }
  11.  
  12. class MyApp extends StatelessWidget {
  13.   @override
  14.   Widget build(BuildContext context) {
  15.     return MaterialApp(
  16.       home: MyHomePage(),
  17.     );
  18.   }
  19. }
  20.  
  21. class MyHomePage extends StatefulWidget {
  22.   MyHomePage({Key key}) : super(key: key);
  23.  
  24.   @override
  25.   _MyHomePageState createState() => _MyHomePageState();
  26. }
  27.  
  28. class _MyHomePageState extends State<MyHomePage> {
  29.   @override
  30.   Widget build(BuildContext context) {
  31.     return Scaffold(
  32.       appBar: PreferredSize(
  33.         child: Text("my app"),
  34.         preferredSize: Size.fromHeight(55.0),
  35.       ),
  36.       body: Container(
  37.         width: MediaQuery.of(context).size.width,
  38.         child: SingleChildScrollView(
  39.           child: Column(
  40.             crossAxisAlignment: CrossAxisAlignment.start,
  41.             children: <Widget>[
  42.               DropDown(),
  43.               Button(),
  44.               // Row(
  45.               //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  46.               //   children: <Widget>[
  47.               //     // Expanded(child: VahaPilota()),
  48.               //     SizedBox(
  49.               //       width: MediaQuery.of(context).size.width * 0.1,
  50.               //     ),
  51.               //     // DeleteBtn(),
  52.               //   ],
  53.               // ),
  54.               // TextVahy(visibility: false),
  55.             ],
  56.           ),
  57.         ),
  58.       ),
  59.     );
  60.   }
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. DropDown.dart file:
  70.  
  71.  
  72.  
  73.  
  74. import 'package:flutter/material.dart';
  75.  
  76. class DropDown extends StatefulWidget {
  77.   @override
  78.   DropDownState createState() => DropDownState();
  79. }
  80.  
  81. class DropDownState extends State<DropDown> {
  82.   List<String> _myList = ["Item 1", "Item 2", "Item 3", "Item 4"];
  83.  
  84.   var currentItemSelected = "Item 1";
  85.  
  86.   @override
  87.   Widget build(BuildContext context) {
  88.     return Center(
  89.       child: Container(
  90.         color: Colors.blue,
  91.         child: ButtonTheme(
  92.           child: DropdownButton<String>(
  93.             dropdownColor: Colors.blue,
  94.             items: _myList.map((String dropDownStringItem) {
  95.               return DropdownMenuItem<String>(
  96.                 value: dropDownStringItem,
  97.                 child: Text(
  98.                   dropDownStringItem,
  99.                 ),
  100.               );
  101.             }).toList(),
  102.             onChanged: (String newItemSelected) {
  103.               setState(() {
  104.                 currentItemSelected = newItemSelected;
  105.                 Button(myText: newItemSelected);
  106.               });
  107.             },
  108.             value: currentItemSelected,
  109.           ),
  110.         ),
  111.       ),
  112.     );
  113.   }
  114. }
  115.  
  116. class Button extends StatefulWidget {
  117.   final String myText;
  118.   Button({this.myText});
  119.  
  120.   @override
  121.   ButtonState createState() => ButtonState();
  122. }
  123.  
  124. class ButtonState extends State<Button> {
  125.   @override
  126.   Widget build(BuildContext context) {
  127.     return Center(
  128.       child: Column(
  129.         children: <Widget>[
  130.           RaisedButton(
  131.             child: Text("Button"),
  132.             onPressed: () {
  133.               // it should update my 'myText' in Text widget below
  134.             },
  135.           ),
  136.           Text(widget.myText == null ? "Default text" : widget.myText),
  137.         ],
  138.       ),
  139.     );
  140.   }
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement