Re-did home_widget.dart -> home_widget2.dart and Dropdown works

This commit is contained in:
Carlos Lopez-Rosario
2020-02-12 20:16:12 -05:00
parent a6beebb4ce
commit 5ba8bf3277
5 changed files with 99 additions and 129 deletions

View File

@@ -1,51 +0,0 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'home_widget.dart';
class DropDownWidget extends StatefulWidget{
@override
_DropDownWidget createState() => _DropDownWidget();
}
class _DropDownWidget extends State<DropDownWidget>{
Item selectedSport;
String curSport;
Color _appBarColor;
List<Item> colorList = <Item>[
const Item("Men's Basketball", Colors.red),
const Item("Women's Basketball", Colors.pinkAccent),
const Item('Baseball', Colors.yellow),
];
@override
Widget build(BuildContext context) {
return DropdownButton<Item>(
value: selectedSport,
icon: Icon(Icons.arrow_drop_down),
iconSize: 24,
style: TextStyle(color: Colors.black),
iconEnabledColor: Colors.white,
onChanged: (Item value) {
setState(() {
selectedSport = value;
curSport = selectedSport.name;
_appBarColor = selectedSport.color;
});
},
items: colorList.map<DropdownMenuItem<Item>>((Item item) {
return DropdownMenuItem<Item>(
value: item,
child: SizedBox(
width: 100,
child: Text(item.name),
),
);
}).toList(),
);
}
String getString(){
return curSport;
}
}

View File

@@ -1,74 +0,0 @@
import 'package:flutter/material.dart';
import 'placeholder_widget.dart';
import 'drop_down_widget.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home>{
int _currentIndex = 0;
var curSport = '';
final List<Widget> _children = [
PlaceholderWidget(Colors.white),
PlaceholderWidget(Colors.orange),
PlaceholderWidget(Colors.blue),
PlaceholderWidget(Colors.red),
PlaceholderWidget(Colors.black38),
];
DropDownWidget ddw = DropDownWidget();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: ddw,
//backgroundColor: ,
),
body: _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: onTabTapped,
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text("Home"),
),
BottomNavigationBarItem(
icon: new Icon(Icons.calendar_today),
title: new Text("Schedule")
),
BottomNavigationBarItem(
icon: new Icon(Icons.table_chart),
title: new Text("Scores")
),
BottomNavigationBarItem(
icon: new Icon(Icons.assessment),
title: new Text("Standings")
),
BottomNavigationBarItem(
icon: new Icon(Icons.more_horiz),
title: new Text("More")
)
],
),
);
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
print(ddw);
});
}
}
class Item {
const Item(this.name, this.color);
final String name;
final Color color;
}

91
lib/home_widget2.dart Normal file
View File

@@ -0,0 +1,91 @@
import 'package:flutter/material.dart';
import 'placeholder_widget.dart';
class Home extends StatelessWidget {
final List<Object> _curSport = ['FootBall', Colors.green];
final List<Item> colorList = <Item>[
const Item("FootBall", Colors.red),
const Item("Soccer", Colors.pinkAccent),
const Item('Baseball', Colors.yellow),
];
final List<Widget> _children = [
PlaceholderWidget(Colors.white),
PlaceholderWidget(Colors.orange),
PlaceholderWidget(Colors.blue),
PlaceholderWidget(Colors.red),
PlaceholderWidget(Colors.black38),
];
@override
Widget build(BuildContext context) {
int _currentBodyIndex = 0;
Item selectedSport;
return StatefulBuilder(
builder: (context, StateSetter setState) => Scaffold(
appBar: AppBar(
centerTitle: true,
title: DropdownButton<Item>(
value: selectedSport,
icon: Icon(Icons.arrow_drop_down),
iconSize: 24,
style: TextStyle(color: Colors.black),
iconEnabledColor: Colors.white,
onChanged: (Item value) {
setState(() {
selectedSport = value;
_curSport[0] = selectedSport.name;
_curSport[1] = selectedSport.color;
});
},
items: colorList.map<DropdownMenuItem<Item>>((Item item) {
return DropdownMenuItem<Item>(
value: item,
child: SizedBox(
width: 100,
child: Text(item.name),
),
);
}).toList(),
),
backgroundColor: _curSport[1],
),
body: _children[_currentBodyIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: (int index) {
setState(() {
_currentBodyIndex = index;
});
},
currentIndex: _currentBodyIndex,
items: [
BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text("Home"),
),
BottomNavigationBarItem(
icon: new Icon(Icons.calendar_today),
title: new Text("Schedule")),
BottomNavigationBarItem(
icon: new Icon(Icons.table_chart),
title: new Text("Scores")),
BottomNavigationBarItem(
icon: new Icon(Icons.assessment),
title: new Text("Standings")),
BottomNavigationBarItem(
icon: new Icon(Icons.more_horiz), title: new Text("More"))
],
),
));
}
}
class Item {
const Item(this.name, this.color);
final String name;
final Color color;
}

View File

@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'home_widget.dart';
import 'home_widget2.dart';
void main() => runApp(App());

View File

@@ -2,8 +2,12 @@ import 'package:flutter/material.dart';
class PlaceholderWidget extends StatelessWidget{
final Color color;
PlaceholderWidget(this.color);
PlaceholderWidget(this.color,);
@override
Widget build(BuildContext context) => Container(color: color,);
}
Widget build(BuildContext context) {
return Container(
color: color,
);
}
}