Skip to content

Commit

Permalink
Added Refracted DropDown Function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya-81199 committed Nov 30, 2020
1 parent 9d54f57 commit 6b86086
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 37 deletions.
2 changes: 2 additions & 0 deletions lib/Screens/Components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Components extends StatefulWidget {
static const String id = "Components";
@override
_MyState createState() => _MyState();

}

class _MyState extends State<Components> {
Expand All @@ -17,6 +18,7 @@ class _MyState extends State<Components> {
);
}


}


Expand Down
135 changes: 100 additions & 35 deletions lib/Screens/Screen_3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,84 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:brokersapp/Screens/Components.dart';



class Screen_3 extends StatefulWidget {
static const String id = "Screen_3";
@override
_MyState createState() => _MyState();
}

class _MyState extends State<Screen_3> {
void Dap(){
print('Hello');

bool val = false;

void setReminder(){
setState(() {

});
val = true;
}
void reset(){
setState(() {

});
val = false;
}
List<String> Properties = ['Property','Property 1','Property 2','Property 3','Property 4','Property 5'];
String topValue = 'Property';
String dropdownValue = 'One';
String Property_default = 'Property';
List<String> Customers = ['Customer','Customer 1','Customer 2','Customer 3','Customer 4','Customer 5'];
String Customer_default = 'Customer';
List<String> Months = ['MM','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
String Month_default = 'MM';
List<String> Dates = ['DD','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'];
String Date_default = 'DD';
List<String> Years = ['YY','2020','2021'];
String Year_default = 'YY';
List<String> Hours = ['HH','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23'];
String Hour_default = 'HH';
List<String> Mins = ['Ms','00','15','30','45'];
String Min_default = 'Ms';


@override
Widget build(BuildContext context) {

return Scaffold(
backgroundColor: Colors.white,
appBar: buildAppBar(context),
body: Center(
body: val ?
Container(
child: AlertDialog(
title: Text('Added Reminder!'),
actions: [
FlatButton(onPressed: () => { reset() }, child: Text("Okay"))
],
)

): Center(
child: Container(
margin: EdgeInsets.all(20.0),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: TextStyle(
color: Colors.deepPurple
),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['One', 'Two', 'Three', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
})
.toList(),
),

buildDropdownButton(Property_default,Properties, 'property'),
buildDropdownButton(Customer_default,Customers,'customer'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildDropdownButton(Month_default, Months,'month'),
buildDropdownButton(Date_default, Dates,'date'),
buildDropdownButton(Year_default, Years,'year')
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildDropdownButton(Hour_default, Hours,'hour'),
buildDropdownButton(Min_default, Mins,'mins'),
],
),
SizedBox(
height: 20,
),
Expand All @@ -80,7 +102,7 @@ class _MyState extends State<Screen_3> {
shadowColor: MaterialStateProperty.all<Color>(Colors.lightGreen),
),
autofocus: true,
onPressed: Dap,
onPressed: setReminder,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Text(
Expand All @@ -99,5 +121,48 @@ class _MyState extends State<Screen_3> {
);
}

DropdownButton<String> buildDropdownButton(String default_name, List<String> names, String fieldname) {

return DropdownButton<String>(
value: default_name,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: TextStyle(
color: Colors.lightGreen
),
underline: Container(
height: 2,
color: Colors.blueGrey[900],
),
onChanged: (String newValue) {
setState(() {
if(fieldname == 'property')
Property_default = newValue;
else if(fieldname == 'customer')
Customer_default = newValue;
else if(fieldname == 'month')
Month_default = newValue;
else if(fieldname == 'date')
Date_default = newValue;
else if(fieldname == 'year')
Year_default = newValue;
else if(fieldname == 'hour')
Hour_default = newValue;
else if(fieldname == 'mins')
Min_default = newValue;
});
},
items: names
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
})
.toList(),
);
}

}

3 changes: 2 additions & 1 deletion lib/Screens/Screen_5.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:brokersapp/Screens/Screen_1.dart';
import 'package:brokersapp/Screens/Screen_4.dart';
import 'package:brokersapp/Screens/Screen_6.dart';
import 'package:brokersapp/Screens/Screen_3.dart';
import 'package:brokersapp/Screens/Components.dart';

class Screen_5 extends StatefulWidget {
Expand Down Expand Up @@ -36,7 +37,7 @@ class _MyState extends State<Screen_5> {
mainAxisAlignment: MainAxisAlignment.spaceAround,
children : [
buildIcon(Icons.home_rounded,null,context),
buildIcon(Icons.add_alert_rounded,null,context),
buildIcon(Icons.add_alert_rounded,Screen_3.id,context),
]
),
SizedBox(
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BrokersApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: Screen_3.id,
initialRoute: Screen_1.id,
routes: {
Screen_1.id : (context) => Screen_1(),
Screen_2.id : (context) => Screen_2(),
Expand Down

0 comments on commit 6b86086

Please sign in to comment.