From 6b86086385f40d353d710b969d8ee96598632e5c Mon Sep 17 00:00:00 2001 From: Priya-81199 Date: Mon, 30 Nov 2020 11:08:53 +0530 Subject: [PATCH] Added Refracted DropDown Function. --- lib/Screens/Components.dart | 2 + lib/Screens/Screen_3.dart | 135 ++++++++++++++++++++++++++---------- lib/Screens/Screen_5.dart | 3 +- lib/main.dart | 2 +- 4 files changed, 105 insertions(+), 37 deletions(-) diff --git a/lib/Screens/Components.dart b/lib/Screens/Components.dart index 91846ad..5de4428 100644 --- a/lib/Screens/Components.dart +++ b/lib/Screens/Components.dart @@ -7,6 +7,7 @@ class Components extends StatefulWidget { static const String id = "Components"; @override _MyState createState() => _MyState(); + } class _MyState extends State { @@ -17,6 +18,7 @@ class _MyState extends State { ); } + } diff --git a/lib/Screens/Screen_3.dart b/lib/Screens/Screen_3.dart index 0031e3e..1b82e79 100644 --- a/lib/Screens/Screen_3.dart +++ b/lib/Screens/Screen_3.dart @@ -2,8 +2,6 @@ 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 @@ -11,19 +9,53 @@ class Screen_3 extends StatefulWidget { } class _MyState extends State { - void Dap(){ - print('Hello'); + + bool val = false; + + void setReminder(){ + setState(() { + + }); + val = true; + } + void reset(){ + setState(() { + + }); + val = false; } List Properties = ['Property','Property 1','Property 2','Property 3','Property 4','Property 5']; - String topValue = 'Property'; - String dropdownValue = 'One'; + String Property_default = 'Property'; + List Customers = ['Customer','Customer 1','Customer 2','Customer 3','Customer 4','Customer 5']; + String Customer_default = 'Customer'; + List Months = ['MM','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec']; + String Month_default = 'MM'; + List 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 Years = ['YY','2020','2021']; + String Year_default = 'YY'; + List 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 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( @@ -31,33 +63,23 @@ class _MyState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - DropdownButton( - 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: ['One', 'Two', 'Three', 'Four'] - .map>((String value) { - return DropdownMenuItem( - 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, ), @@ -80,7 +102,7 @@ class _MyState extends State { shadowColor: MaterialStateProperty.all(Colors.lightGreen), ), autofocus: true, - onPressed: Dap, + onPressed: setReminder, child: Padding( padding: const EdgeInsets.all(15.0), child: Text( @@ -99,5 +121,48 @@ class _MyState extends State { ); } + DropdownButton buildDropdownButton(String default_name, List names, String fieldname) { + + return DropdownButton( + 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>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }) + .toList(), + ); + } + } diff --git a/lib/Screens/Screen_5.dart b/lib/Screens/Screen_5.dart index d984b10..2624b2f 100644 --- a/lib/Screens/Screen_5.dart +++ b/lib/Screens/Screen_5.dart @@ -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 { @@ -36,7 +37,7 @@ class _MyState extends State { 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( diff --git a/lib/main.dart b/lib/main.dart index c366cab..fe15c88 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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(),