This is where I call API:
class Hisseler extends StatefulWidget {
const Hisseler({Key? key}) : super(key: key);
@override
State<Hisseler> createState() => _HisselerState();
}
class _HisselerState extends State<Hisseler> {
final scaffoldKey = GlobalKey<ScaffoldState>();
final url = Uri.parse('https://api.collectapi.com/economy/hisseSenedi');
var counter;
Hisselist? hisseResult;
Future callHisse() async {
try{
Map<String, String> requestHeaders = {
'Content-Type': 'application/json',
'Authorization': 'apikey xxx'
};
final response = await http.get(url,headers:requestHeaders);
if(response.statusCode == 200){
var result = hisselistFromJson(response.body);
if(mounted);
setState(() {
counter = result.result.length;
result.result.sort((a, b) => (a.text ?? "").compareTo(b.text ?? ""));
hisseResult = result;
});
return result;
} else {
print(response.statusCode);
}
} catch(e) {
print(e.toString());
}
}
@override
void initState() {
// TODO: implement initState
super.initState();
callHisse();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: false,
automaticallyImplyLeading: false,
title: Text(
'Hisseler'
),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: counter != null ?
ListView.separated(
itemCount: counter,
separatorBuilder: (context, index) {
return Divider(color: Colors.grey[400]);
},
itemBuilder: (context, index){
return Card(
child: ListTile(
contentPadding: EdgeInsets.all(10),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text((hisseResult?.result[index].code ?? "")
.replaceAll("https:", ""),
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w500)),
Text(hisseResult?.result[index].text??"",style: TextStyle(color: Colors.grey[500], fontSize: 14))
],
),
trailing: Column(
children: <Widget>[
Text(hisseResult?.result[index].lastpricestr??"", style: TextStyle(color: Colors.black, fontSize: 16, fontWeight: FontWeight.w500)),
Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: (hisseResult?.result[index].rate ?? 0) > 0
? Colors.green
: Colors.red),
width: 75,
height: 25,
child: Text(hisseResult?.result[index].rate.toString()??"",style: TextStyle(color: Colors.white))
),
],
),
onTap: () => Navigator.push(
context, MaterialPageRoute(builder: (context) => StocksDetailScreen( text: '', code: '', rate: '', lastpricestr: '',))),
),
);
}) : Center(child: CircularProgressIndicator(
)),
),
),
);
}
}
I want to create a detail page for this page, I try this as a test:
class StocksDetailScreen extends StatelessWidget {
final String rate;
final String lastpricestr;
final String code;
final String text;
const StocksDetailScreen({
Key? key,
required this.rate,
required this.code,
required this.text,
required this.lastpricestr,
}) : super(key: key);
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(rate,style: TextStyle(fontSize: 18, fontWeight: FontWeight.w900),),
),
body: SafeArea(
bottom: true,
top: false,
maintainBottomViewPadding: true,
child: Column(
children: [
Expanded(
child: CustomScrollView(
slivers: <Widget>[
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(rate,style: TextStyle(fontSize: 18, fontWeight: FontWeight.w900),), ],
),
),
),
Divider(height: 3.6,),
SizedBox(height: 50,),
Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Text(code,style: TextStyle(fontSize: 20,fontWeight: FontWeight.w600), textAlign: TextAlign.center,),
),
)
],
),
),
],
),
),
// -- Banner ads --
context.watch<AdsBloc>().bannerAdEnabled == false ? Container()
: BannerAdAdmob() //admob
//: BannerAdFb() //fb
],
),
)
);
}
}
No errors in the console or anywhere but I get a white screen. How can I fix this?
CodePudding user response:
I've fixed it with:
onTap: () => Navigator.push(
context, MaterialPageRoute(builder: (context) => StocksDetailScreen(
degisimoran: hisseResult?.result[index].rate.toString()??"",
sondeger: hisseResult?.result[index].lastpricestr??"",
hacim: hisseResult?.result[index].hacimstr ?? "",
mindeger : hisseResult?.result[index].minstr?? "",
maxdeger : hisseResult?.result[index].maxstr?? "",
zaman : hisseResult?.result[index].time.toString()?? "",
hisseismi : hisseResult?.result[index].text?? "",
hissekodu : hisseResult?.result[index].code?? "",
)),),
And on the detail page:
class StocksDetailScreen extends StatelessWidget {
final String degisimoran;
final String? sondeger;
final String? hacim;
final String? mindeger;
final String maxdeger;
final String? zaman;
final String? hisseismi;
final String? hissekodu;
const StocksDetailScreen({
Key? key,
required this.degisimoran,
required this.sondeger,
required this.hacim,
required this.mindeger,
required this.maxdeger,
required this.zaman,
required this.hisseismi,
required this.hissekodu,
}) : super(key: key);
Now i can call all data from API.