I am currently building a botcoin ticker app that returns a list of currencies to a dropDown menu . I am getting the following errors:-
error: The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type. (body_might_complete_normally at [bitcoin_ticker] lib\price_screen.dart:10)
error: The argument type 'List<DropdownMenuItem>' can't be assigned to the parameter type 'List<DropdownMenuItem>?'. (argument_type_not_assignable at [bitcoin_ticker] lib\price_screen.dart:60)
Here is my code
import 'package:flutter/material.dart';
import 'coin_data.dart';
int i = 0;
class PriceScreen extends StatefulWidget {
@override
_PriceScreenState createState() => _PriceScreenState();
}
List<DropdownMenuItem> getDropDownItems() {
List<DropdownMenuItem<String>> dropdownItem = [];
for (String currency in currenciesList) {
DropdownMenuItem(
child: Text(currency), //
value: currency,
);
}
}
class _PriceScreenState extends State<PriceScreen> {
late String selectedCurrency = 'USD';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(' Coin Ticker'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(18.0, 18.0, 18.0, 0),
child: Card(
color: Colors.lightBlueAccent,
elevation: 5.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 28.0),
child: Text(
'1 BTC = ? USD',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
),
),
),
Container(
height: 150.0,
alignment: Alignment.center,
padding: EdgeInsets.only(bottom: 30.0),
color: Colors.lightBlue,
child: DropdownButton<String>(
value:selectedCurrency,//Default value
items: getDropDownItems(),
onChanged:(value){//it is like an on Pressed Button
setState(() {
selectedCurrency = value!;
print(selectedCurrency);
});
},
),
),
],
),
);
}
}