0

I have a specialDialog in dart that when clicking on the FlatButton displays an error message in the emulator "The relevant error-causing widget was ScheduleReturn"

  specialDialog(BuildContext context, String? agent_id) {
// set up the buttons
Widget coverageButton = FlatButton(
  child: Text("Solicitar cobertura"),
  onPressed: () {
    localRequestCoverage(agent_id);
  },
);
Widget returnButton = FlatButton(
  child: Text("Solicitar devolución"),
  onPressed: () {
    Route route = MaterialPageRoute(
        builder: (context) => ScheduleReturn(schedule: widget.schedule));
    Navigator.pushReplacement(context, route);
  },
);
2
  • Can you include localRequestCoverage Commented Aug 17, 2022 at 12:25
  • The bug would be in ScheduleReturn then probably. Show us ScheduleReturn. In any case, the bug simply means you use ! on a variable that is null Commented Aug 17, 2022 at 12:29

4 Answers 4

1

Instead of using ! directly do a null check before it. also you can provide default value on null case like

 Text( (widget.day_name??"") + ' ' + (widget.day?? "")  + ' ' + (widget.month_name??"")  + ' ' + ( widget.schedule_change??""),

Or better directly use String format.

Text(
  "${widget.day_name} ${widget.day} ",

Also, you can assign value on null case

Sign up to request clarification or add additional context in comments.

Comments

0

I include ScheduleReturn code:

import 'package:flutter/material.dart';
import 'package:sig/listview/schedule_return_listview.dart';

class ScheduleReturn extends StatefulWidget {

  ScheduleReturn({Key? key, this.schedule, this.day, this.day_name, this.month_name, this.schedule_change}) : super(key: key);
  final String? schedule;
  final String? day;
  final String? day_name;
  final String? month_name;
  final String? schedule_change;

  @override
  _ScheduleReturn createState() => _ScheduleReturn();

}

class _ScheduleReturn extends State<ScheduleReturn> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          backgroundColor: Colors.black87,
          title: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                'Devolución de horario',
                style: TextStyle(color: Colors.white, fontSize: 16.0),
              ),
              Text(
                widget.day_name! + ' ' + widget.day! + ' ' + widget.month_name! + ' ' + widget.schedule_change!,
                style: TextStyle(fontSize: 10, fontWeight: FontWeight.w500),
              )
            ],
          ),
        ),
        body: Column(
          children: [
            new Expanded(
              child:Container(
                  margin: const EdgeInsets.only(top: 0.0),
                  child: new Center(
                    child: ScheduleReturnListView(schedule: widget.schedule),

Comments

0

change this :

Text(
                widget.day_name! + ' ' + widget.day! + ' ' + widget.month_name! + ' ' + widget.schedule_change!,
                style: TextStyle(fontSize: 10, fontWeight: FontWeight.w500),
              )

to this:

Text(
               '${widget.day_name}' + ' ' + '${widget.day}' + ' ' + '${widget.month_name}' + ' ' + '${widget.schedule_change}',
                style: TextStyle(fontSize: 10, fontWeight: FontWeight.w500),
              )

Comments

0

In code, Wherever you use agent_id with !(null-aware-operator), at that place you got null for agent id. You are getting null value, where you are using !(null-aware-operator) to unwrap the data.

So, You need to check value passing at that line in code.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.