skip to Main Content

Help mee plisss, I have been trying fixes for the last couple of hours, but nothing is working. Does anyone know exactly where to apply a fix and what is the fix?

HOMEPAGE

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  late final stream = FirebaseDatabase.instance.ref('sensor/').onValue;

  int counter = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: SingleChildScrollView(
        child: Stack(
          children: [
            StreamBuilder(
              stream: stream,
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  final data = snapshot.data?.snapshot.value as Map?;
                  if (data == null) {
                    return Text('No data');
                  }
                  final sensorEC = data['EC'];
                  final sensorPH = data['PH'];
                  final sensorRTD = data['RTD'];
                  final humidity = data['humidity'];
                  final temperature = data['temperature'];
                  return Stack(
                    children: [
                      Container(
                        margin: EdgeInsets.only(top: 70, left: 10),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              "SHOWCASE",
                              style: whiteTextStyle.copyWith(
                                  fontSize: 20, fontWeight: bold),
                            ),
                            Spacer(),
                            Icon(
                              Icons.account_circle,
                              size: 30,
                              color: Colors.blueGrey,
                            ),
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(
                          top: 110,
                          left: 10,
                        ),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                              child: Text(
                                "Water Management",
                                style: whiteTextStyle.copyWith(fontSize: 16),
                              ),
                            ),
                            SizedBox(
                              height: 10,
                            ),
                            Container(
                              child: Row(
                                children: [
                                  ParamWaterManagement(
                                    nameSensor: 'EC',
                                    valueSensor: '$sensorEC',
                                  ),
                                  ParamWaterManagement(
                                      nameSensor: 'PH',
                                      valueSensor: '$sensorPH'),
                                  ParamWaterManagement(
                                      nameSensor: 'RTD',
                                      valueSensor: '$sensorRTD'),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(
                          top: 200,
                          left: 10,
                        ),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                              child: Text(
                                "Water Climate",
                                style: whiteTextStyle.copyWith(fontSize: 16),
                              ),
                            ),
                            SizedBox(
                              height: 10,
                            ),
                            Container(
                              child: Row(
                                children: [
                                  ParamWaterClimate(
                                    nameSensor: 'humidity',
                                    valueSensor: '$humidity',
                                  ),
                                  ParamWaterClimate(
                                      nameSensor: 'temperature',
                                      valueSensor: '$temperature'),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  );
                }
                if (snapshot.hasError) {
                  print(snapshot.error.toString());
                  return Text(snapshot.error.toString());
                }

                return Text('....');
              },
            ),
          ],
        ),
      ),
    );
  }
}

WIDGET WATER MANAGEMENT


class ParamWaterManagement extends StatelessWidget {
  final String nameSensor;
  final String valueSensor;

  ParamWaterManagement({Key? key, required this.nameSensor, required this.valueSensor});

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      width: 110,
      height: 55,
      margin: const EdgeInsets.only(
        right: 7,
      ),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(5),
        color: kPrimaryColor,
      ),
      child: Padding(
        padding: const EdgeInsets.all(4.0),
        child: Expanded(
          child: Column(children: [
            Expanded(
              child: Text(
                '$nameSensor (μS/cm)',
                style: whiteTextStyle.copyWith(
                    fontSize: 12,
                    fontWeight: bold,
                    decoration: TextDecoration.none),
              ),
            ),
            const SizedBox(
              height: 6,
            ),
            Text(
              '$valueSensor',
              style: neonBasicStyle.copyWith(
                fontSize: 17,
                fontWeight: bold,
                decoration: TextDecoration.none,
              ),
            )
          ]),
        ),
      ),
    );
  }
}

WIDGET WATERCLIMATE


class ParamWaterClimate extends StatelessWidget {
  final String nameSensor;
  final String valueSensor;

  ParamWaterClimate({Key? key, required this.nameSensor, required this.valueSensor});

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.centerLeft,
      width: 120,
      height: 55,
      margin: EdgeInsets.only(
        right: 7,
      ),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(5),
        color: kPrimaryColor,
      ),
      child: Padding(
        padding: const EdgeInsets.all(4.0),
        child: Expanded(
          child: Column(children: [
            Expanded(
              child: Text(
                "$nameSensor (μS/cm)",
                style: whiteTextStyle.copyWith(
                  fontSize: 12,
                  fontWeight: bold,
                  decoration: TextDecoration.none,
                ),
              ),
            ),
            SizedBox(
              height: 6,
            ),
            Text(
              '$valueSensor',
              style: neonBasicStyle.copyWith(
                fontSize: 17,
                fontWeight: bold,
                decoration: TextDecoration.none,
              ),
            )
          ]),
        ),
      ),
    );
  }
}

Another exception was thrown: Incorrect use of Parent Data Widget flutter for details can you help meee

2

Answers


  1. Remove Expended Widget from Text

     Expanded(
      child: Text(
        $nameSensor (μS/cm)',
        style: whiteTextStyle.copyWith(
        fontSize: 12,
        fontWeight: bold,
        decoration: TextDecoration.none),
      ),
    

    ),

    if not working then remove expended widget from Column

     Expanded(
          child: Column(children: [
            Expanded(
              child: Text(
                "$nameSensor (μS/cm)",
                style: whiteTextStyle.copyWith(
                  fontSize: 12,
                  fontWeight: bold,
                  decoration: TextDecoration.none,
                ),
              ),
            ),
            SizedBox(
              height: 6,
            ),
            Text(
              '$valueSensor',
              style: neonBasicStyle.copyWith(
                fontSize: 17,
                fontWeight: bold,
                decoration: TextDecoration.none,
              ),
            )
          ]),
        ),
    
    Login or Signup to reply.
  2. The error is happening because you are using expanded widget directly inside padding widget in ParamWaterClimate class.
    Remove expanded widget and it will not leave any error behind.

    class ParamWaterClimate extends StatelessWidget {
     final String nameSensor;
     final String valueSensor;
    
     const ParamWaterClimate(
      {super.key, required this.nameSensor, required this.valueSensor});
    
     @override
     Widget build(BuildContext context) {
       return Container(
        alignment: Alignment.centerLeft,
        width: 120,
        height: 55,
        margin: const EdgeInsets.only(right: 7),
        decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(5),
        color: Colors.grey,
        ),
       padding: const EdgeInsets.all(8.0),
       child: Column(
         children: [
           Expanded(
             child: Text(
              "$nameSensor (μS/cm)",
              style: const TextStyle(
                fontSize: 12,
                fontWeight: FontWeight.bold,
                decoration: TextDecoration.none,
              ),
            ),
          ),
          const SizedBox(height: 6),
          Text(valueSensor)
        ],
      ),
     );
    }
    }
    

    Hope it helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search