long1eu / circle_indicator

Small library that build a circle indicator for the PagerViewer. This can be used in Android and iOS apps.
BSD 3-Clause "New" or "Revised" License
38 stars 14 forks source link

Next/Complete Button #1

Closed Solido closed 7 years ago

Solido commented 7 years ago

I've already integrated it in my project. I miss a next button to the right to move from screen to screen. Also when on the last screen the label and action can change to finish/complete event listener so we can close the presentation view. What you think about it ?

long1eu commented 7 years ago

Thanks! Good point. In my project I do use a widget to navigate to another page. I'll add that right away. A name constructor would be fine?

long1eu commented 7 years ago

🤣 so I don't think I can integrate it in the Circle Widget. In my project I add it to the main page logic like this:

class StartPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => new _StartPageState();

}

class _StartPageState extends State<StartPage> {

  final PageController controller = new PageController();

  Stack rootWidget;
  bool showStart = false;
  int previousPage = 0;

  @override
  Widget build(BuildContext context) {
    rootWidget = createPages();
    controller.addListener(pagerListener);

    return new Scaffold(
      body: new Container(
        padding: new EdgeInsets.only(top: 16.0,),
        decoration: new BoxDecoration(
            color: primaryColor
        ),
        child: rootWidget,
      ),
    );
  }

  Stack createPages() {
    var pageList = <StartPageItem>[
      new StartPageItem("assets/ic_info_01.png"),
      new StartPageItem("assets/ic_info_02.png"),
      new StartPageItem("assets/ic_info_03.png"),
      new StartPageItem("assets/ic_info_04.png"),
      new StartPageItem("assets/ic_info_05.png"),
      new StartPageItem("assets/ic_info_06.png"),
      new StartPageItem("assets/ic_info_07.png"),
      new StartPageItem("assets/ic_info_08.png"),
    ];

    var childrenList = <Widget>[
      new PageView.builder(
        controller: controller,
        itemCount: pageList.length,
        itemBuilder: (_, int i) => pageList[i],
      ),
      new Container(
        margin: new EdgeInsets.only(
          top: 16.0,
          bottom: 16.0,
        ),
        child: new CircleIndicator(
            controller, pageList.length, 3.0,
            Colors.white70, Colors.white),
      ),
    ];

    if (showStart) {
      childrenList.add(
        new Container(
          alignment: FractionalOffset.bottomRight,
          margin: new EdgeInsets.all(16.0),
          child: new GestureDetector(
            onTap: startApp,
            child: new Text("START",
              style: Theme
                  .of(context)
                  .textTheme
                  .body1
                  .copyWith(
                color: Colors.white,
                fontFamily: "DancingScript-Regular",
              ),
            ),
          ),
        ),
      );
    }

    return new Stack(
      alignment: FractionalOffset.bottomCenter,
      children: childrenList,
    );
  }

  void pagerListener() {
    setState(() => showStart = controller.page == 7);
  }

  void startApp() {
    Navigator.popAndPushNamed(context, HomePage.routeName);
  }
}
Solido commented 7 years ago

I guess you can provide the widget like you do now but also a global page wrapper

Solido commented 7 years ago

Something like new IntroductionView and the constructor take the PageList and the final action as parameters

long1eu commented 7 years ago

ooo, nice, so you only need to provide the pages, ok

Solido commented 7 years ago
new CircleIntroduction( <Widget>[], onComplete => // Fade or navigate somewhere else )
long1eu commented 7 years ago

perfect

long1eu commented 7 years ago

Done, you can check it now.

Solido commented 7 years ago

Tested and it works great 👍

long1eu commented 7 years ago

Can you close this issue?