Jals
Jals

Reputation: 290

Flutter : How to use router on dialog

First i have a button to open a dialog enter image description here

When clicking on repeat i want to user navigator push a page on dialog like thisenter image description here

How can't i do that with flutter? Thanks for your help!

Upvotes: 2

Views: 2344

Answers (2)

Diwyansh
Diwyansh

Reputation: 3514

You can use PageView.builder with PageController to achieve your expected result. I'm sharing a reference example you can modify it as per your need.

class WelcomeScreen extends StatefulWidget {
  @override
  _WelcomeScreenState createState() => _WelcomeScreenState();
}

class _WelcomeScreenState extends State<WelcomeScreen> {
  PageController _controller = PageController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Pagination Example"),
      ),
      body: Padding(
        padding: EdgeInsets.all(24.0),
        child: Center(
          child: PageView.builder(
              controller: _controller,
              itemCount: 2,
              itemBuilder: (context, index) => Scaffold(
                    appBar: AppBar(
                      title: Text("Page $index"),
                      leading: index == 1
                          ? IconButton(
                              onPressed: () {
                                _controller.previousPage(
                                    duration: Duration(milliseconds: 100),
                                    curve: Curves.ease);
                              },
                              icon: Icon(Icons.arrow_back),
                            )
                          : null,
                    ),
                    body: Column(
                      children: [
                        Text("Content of Page $index"),
                        Visibility(
                          visible: index == 1 ? false : true,
                          child: ElevatedButton(
                              onPressed: () {
                                _controller.nextPage(
                                    duration: Duration(milliseconds: 100),
                                    curve: Curves.ease);
                              },
                              child: Text("Next Page")),
                        )
                      ],
                    ),
                  )),
        ),
      ),
    );
  }
}

Upvotes: 2

The Night Baron
The Night Baron

Reputation: 1

Have you tried changing the content of the dialog instead of using the router? like using a state variable that changes when you click on repeat updating the dialog content then restoring it when you click save

Upvotes: 0

Related Questions