0
selectedDateTime != null //if true
                        ? Container(
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                          colors: [Colors.grey, Colors.black87],
                        ),
                        color: Colors.white70,
                        borderRadius: BorderRadius.circular(20),
                      ),
                      height: 50,
                      width: 300,
                      child: Row(
                        children: [
                          Container(
                            height: 40,
                            width: 30,
                            child: Image.asset('lib/icons/hourglass.png'),
                          ),
                          SizedBox(width: 15,),
                          Text(selectedDateTime!.day.toString()+"/"+selectedDateTime!.month.toString()+selectedDateTime!.year.toString()
                            +" - "+selectedDateTime!.hour.toString()+":"+selectedDateTime!.minute.toString()
                            , style: GoogleFonts.outfit(fontSize: 20),),
                          SizedBox(width: 45,),
                          GestureDetector(
                            onTap: (){
                              setState(() {
                                selectedDateTime=null;
                              });
                            },
                            child: Container(
                              height: 40,
                              width: 30,
                              child: Image.asset('lib/icons/remove.png'),
                            ),
                          ),
                        ],
                      ),
                    )//if false
                        : Container(
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                          colors: [Colors.deepPurple, Colors.greenAccent],
                        ),
                        color: Colors.white70,
                        borderRadius: BorderRadius.circular(20),
                      ),
                      height: 50,
                      width: 300,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          Text('Set Reminder', style: GoogleFonts.outfit(fontSize: 20),),
                          Container(
                            height: 40,
                            width: 40,
                            child: Image.asset('lib/icons/clock.png'),
                          ),
                        ],
                      ),
                    ),
                  ),

When I change the selecteddatetime variable it does not chang the container on the first go but when I click on the textfield above it , the container changes

MendelG
  • 14,885
  • 4
  • 25
  • 52

1 Answers1

0

It is hard to find the issue when the code is not complete. You should provide a complete code (all of the codes in that file) for people to help.

If this is a stateful widget, add setState({selectedDateTime = "something"}) in where the selectedDateTime is updated, to make sure that the widget gets re-rendered when selectedDateTime is updated with a new value.

Untung
  • 1
  • 2