13.3 C
New York
Tuesday, March 25, 2025

android – Flutter – change button youngster alignment inside column primarily based on situation


May use some assist right here. I’ve been making an attempt to get this to work in Flutter and tried various totally different options I’ve discovered on-line, none of which have labored. I want a button that’s centered within the display screen to maneuver to the underside of the web page after it has been pressed.

class _ReportStressorState extends State {
  bool disableNextButton = false;
  Checklist stressorForms = [];

  @override
  Widget construct(BuildContext context) {
    return Scaffold(
      physique: Heart(
        youngster: SizedBox(
          width: MediaQuery.of(context).measurement.width * 0.9,
          top: MediaQuery.of(context).measurement.top * 0.75,
          youngster: Stack(
            kids: [
              Column(
                children: [
                  const ProgressBar(numberOfStages: 4, currentStage: 2),
                  Builder(
                    builder: (BuildContext context) {
                      if (stressorForms.isNotEmpty) {
                        return Expanded(
                          child: ListView.builder(
                            itemCount: stressorForms.length,
                            itemBuilder: (context, index) {
                              return stressorForms[index];
                            },
                          ),
                        );
                      } else {
                        return const SizedBox.shrink();
                      }
                    },
                  ),
                  Align(
                    alignment: Alignment.heart,
                    youngster: PlatformElevatedButton(
                      onPressed: () {
                        setState(() {
                          stressorForms.add(const StressorForm());
                        });
                        disableNextButton = true;
                      },
                      colour: Colours.orange,
                      youngster: Padding(
                        padding: const EdgeInsets.fromLTRB(20.0, 5.0, 20.0, 5.0),
                        youngster: Textual content("+ Add a stressor",
                            fashion: TextStyle(
                                fontSize: MediaQuery.of(context).measurement.width * 0.04,
                                colour: Colours.white)),
                      ),
                    ),
                  )
                ],
              ),
            ],
          )
        ),
      ),
    );
  }

This leads to the next show. Discover the button is just not centered right here.

enter image description here

If I don’t wrap the column in a Stack() widget, and use as a substitute:

Column(mainAxisAlignment: MainAxisAlignment.heart,

I get the next, however I want the progress bar to stay on the high of the display screen.

I’ve additionally tried utilizing two columns beneath the SizedBox() and this doesn’t work both. Thanks!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles