Working in flutter and having issues getting my code to work. it was working previously and it was getting a parent widget error and unbounded errors. I had some formatting issues i was working through with the appbar I was working through. currently I have the app bar working as I want it, but nothing will render below, and I am getting an error telling me i cant be null, but i cant figure out why not? and what i need to do to get it to work.
My code: main:
import 'package:flutter/material.dart';
import 'package:percent_indicator/percent_indicator.dart';
import 'widgets/alertsfeeddata.dart';
import 'widgets/bullbearindicator.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: Scaffold(
appBar: AppBar(
title: Padding(
padding: const EdgeInsets.all(75),
child: Image.asset('assets/logos/1.png'),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(5),
child: Container(
color: Colors.black,
height: 5,
child: Container(
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(width: 5, color: Colors.green),
),
),
),
),
),
),
backgroundColor: Colors.black,
body: Column(
children: <Widget>[
const BullBearIndicator(
key: null,
),
Align(
child: Expanded(
child: ListView(children: <Widget>[
Container(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularPercentIndicator(
radius: 45.0,
lineWidth: 4.0,
percent: 0.10,
center: const Text("10%"),
backgroundColor: Colors.red,
progressColor: Colors.green,
),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
),
CircularPercentIndicator(
radius: 45.0,
lineWidth: 4.0,
percent: 0.30,
center: const Text("30%"),
progressColor: Colors.orange,
),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
),
CircularPercentIndicator(
radius: 45.0,
lineWidth: 4.0,
percent: 0.60,
center: const Text("60%"),
progressColor: Colors.yellow,
),
Padding(
padding: const EdgeInsets.all(30.0),
child: WebhookDataList(),
),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
),
],
),
)
]),
),
),
],
),
),
);
}
}
BullBearIndicator:
import 'package:flutter/material.dart';
import 'package:percent_indicator/percent_indicator.dart';
class BullBearIndicator extends StatelessWidget {
final double totAggr;
final double btc;
final double eth;
final double alt;
const BullBearIndicator({
required Key key,
this.totAggr = 0.88,
this.btc = 0.71,
this.eth = 0.71,
this.alt = 0.78,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return CircularPercentIndicator(
radius: 130.0,
animation: true,
animationDuration: 1200,
lineWidth: 15.0,
percent: totAggr,
center: CircularPercentIndicator(
radius: 108.0,
lineWidth: 12.5,
animation: true,
percent: btc,
center: CircularPercentIndicator(
radius: 90.0,
lineWidth: 12.5,
animation: true,
percent: eth,
center: CircularPercentIndicator(
radius: 72,
lineWidth: 12.5,
percent: alt,
center: totAggr > 0.51
? Image.asset('assets/logos/bull.png')
: Image.asset('assets/logos/bear.png'),
backgroundColor: Colors.red,
progressColor: Colors.green,
),
circularStrokeCap: CircularStrokeCap.butt,
backgroundColor: Colors.red,
progressColor: Colors.green,
),
circularStrokeCap: CircularStrokeCap.butt,
backgroundColor: Colors.red,
progressColor: Colors.green,
),
footer: const Text(
"BULL/BEAR",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17.0),
),
circularStrokeCap: CircularStrokeCap.round,
backgroundColor: Colors.red,
progressColor: Colors.green,
);
}
}
CodePudding user response:
Try the following code:
const BullBearIndicator(),
Also, you need to change your code to:
const BullBearIndicator({
this.totAggr = 0.88,
this.btc = 0.71,
this.eth = 0.71,
this.alt = 0.78,
super.key,
})
or
const BullBearIndicator({
Key? key,
this.totAggr = 0.88,
this.btc = 0.71,
this.eth = 0.71,
this.alt = 0.78,
}) : super(key: key);