How call the function Widget build(BuildContext context) on the same page?

Viewed 37

My question is how can i call this functionWidget build(BuildContext context) inside another one on the same one : so i have a code similar to this :

@override
  Widget build(BuildContext context) {
    Widget build(BuildContext context) {
      return !firstCondition!
          ? !secondCondition!
              ? Column(
                  children: [
                    //treatment1
                  ],
                )
              : Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        InkWell(
                          onTap: () {
                            // load the function widget build and test if the firstCondition is true or not if true test the second one 
                          },
                          child: AnimatedContainer(
                            duration: const Duration(milliseconds: 400),
                            height: MediaQuery.of(context).size.height * 0.08,
                            margin: const EdgeInsets.symmetric(horizontal: 5),
                            width: MediaQuery.of(context).size.height * 0.18,
                            decoration: BoxDecoration(
                              color: const Color(0xFF008DFF),
                              borderRadius: BorderRadius.circular(10),
                            ),
                            child: const Center(
                              child: Text(
                                "Relancer",
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 17,
                                  fontFamily: 'SFProRegular',
                                ),
                              ),
                            ),
                          ),
                        ),
                        InkWell(
                          onTap: () {
                            //treatment
                          },
                          child: AnimatedContainer(
                            duration: const Duration(milliseconds: 400),
                            height: MediaQuery.of(context).size.height * 0.08,
                            margin: const EdgeInsets.symmetric(horizontal: 5),
                            width: MediaQuery.of(context).size.height * 0.18,
                            decoration: BoxDecoration(
                              color: const Color(0xFFE5E5EA),
                              borderRadius: BorderRadius.circular(10),
                            ),
                            child: const Center(
                              child: Text(
                                "Abandonner",
                                style: TextStyle(
                                  color: Colors.black87,
                                  fontSize: 17,
                                  fontFamily: 'SFProRegular',
                                ),
                              ),
                            ),
                          ),
                        )
                      ],
                    )
                  ],
                )
          : Column(
              children: [
                //widget text
              ],
            );
    }
  }

what i want to do is if i tap on button "Relancer" i want to do the test in the beginning of the function Widget build(BuildContext context) Or simply i want to execute the //treatment1 because i khnow the value of firstCondition and the secondCondition .

1 Answers

try this in your onTap:

    onTap: () {
setState({     firstCondition =true; });
                          
                              },

your build function will rebuild an condition will be rechecked.

Related