Hello guys I am new on flutter and building a new app... I have a problem that I cannot do it... I want to call elements of List from another class, I wrote some code but I could not call to another class please answer me... I need your help...
EXPLAIN OF PROJECT: I have a bottom navigation bar. First Screen 'Details', I want to show 'status' of element of List. Second Screen 'Profile', I want to show 'year' of element of List. First Screen
I have List 'SERVIS_IHALE_DATA' and constructor 'IhaleData'. These are my datas and I want to call them from another class.
The LIST and CONSTRUCTOR:
const SERVIS_IHALE_DATA = [
IhaleData(
id: 'User1',
brand: 'Volkswagen',
year: '2011',
status: 'Onarım'
),
];
class IhaleData {
final String id;
final String brand;
final String year;
final String status;
const IhaleData(
{
this.id,
this.brand,
this.year,
this.status
});
}
And I have 'ServisKartDetay' class and call from 'ServisKartDetay' class:
class ServisKartDetay extends StatefulWidget {
final IhaleData ihaleData;
ServisKartDetay(this.ihaleData);
@override
_ServisKartDetayState createState() => _ServisKartDetayState();
}
class _ServisKartDetayState extends State<ServisKartDetay> {
int _selectedIndex = 0;
final List<Widget> _selectedItem = <Widget>[
IlanBilgileri(
IhaleData(),
), //ERROR IS HERE
Container(
child: Center(
child: Text('Screen 2'),
),
)
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(body:Container(
Text(widget.ihaleData.status),
),
bottomNavigationBar: Theme(
data: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent),
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.white,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.details),
title: Text('Details'),
),
BottomNavigationBarItem(
icon: Icon(Icons.info),
title: Text('Profile'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.red,
onTap: _onItemTapped,
),
),
);
}
this code is working but my problem is starting here because in a way I don't understand it is not working:
OTHER CLASS 'IlanBilgileri':
class IlanBilgileri extends StatefulWidget {
final IhaleData kartDetay;
IlanBilgileri(this.kartDetay);
@override
_IlanBilgileriState createState() => _IlanBilgileriState();
}
class _IlanBilgileriState extends State<IlanBilgileri> {
@override
Widget build(BuildContext context) {
return Container(child:Text( widget.kartDetay.status == null
? widget.kartDetay.status.toString()
: 'Hello',
);
}
}
it is not giving me error or anything else, it returns null... and I did not understand that's why... I am calling from 'IlanBilgileri' to 'ServisKartDetay' as a page of bottom navigation bar... but it is giving me null...
I hope I could explain...