Pageview with Pagecontroller in Flutter

Asked

Viewed 828 times

0

Please someone tell me why the buttons that should go through the screens are not working right. I tested on an android emulator and on an android phone and nothing to correctly pass the view.

import 'package:flutter/material.dart';

import 'PageViewController.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter PageView Demonstratio',
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      home: HomeWidget(),
    );
  }
}

class HomeWidget extends StatefulWidget {
  @override
  _HomeWidgetState createState() => _HomeWidgetState();
}

class _HomeWidgetState extends State<HomeWidget> {
  PageController controller;

  @override
  void initState() {
    super.initState();
    controller = PageController(initialPage: 0);
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    List<String> pages = ["BATATA", "CENOURA", "MAGERICÃO"];
    return Scaffold(
        appBar: AppBar(
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.keyboard_arrow_left),
              onPressed: () {
                controller.previousPage(
                    curve: Curves.easeInOutBack,
                    duration: Duration(milliseconds: 300));
              },
            ),

          IconButton(
              icon: Icon(Icons.home),
              onPressed: () {
                controller.jumpToPage(0);
              },
            ),

            IconButton(
              icon: Icon(Icons.keyboard_arrow_right),
              onPressed: () {
                controller.nextPage(
                    curve: Curves.easeInOutBack,
                    duration: Duration(milliseconds: 300));
              },
            ),
          ],
          title: Text("Page View"),
        ),
        body: PageView.builder(
          controller: controller,
          itemCount: pages.length,
          itemBuilder: (BuildContext context, int index) {
            print(index);
            return Center(child: Text(pages[index]));
          },
        ));
  }
}
  • Now that I saw sorry, I removed my answer because it is simpler that I saw, it makes the following switch to animicao from Curves to Ease, for some reason that I have not yet discovered with this animation easeOutBack it does not Vanca.

  • Yes, that’s what it was.

  • Thanks a lot, bro!

  • Must be a Flutter bug or something

  • but it’s interesting you put as an answer so I can close the question

  • You should answer the question yourself, it was something very simple. Just put what was the problem and ready answered

  • @Justcase In case Marcos was right... You found the solution, so it would be interesting to put together an answer showing where the change is to be made giving a brief explanation.

Show 2 more comments

1 answer

0


@Justcase fixed the problem:

makes the following change the animation from Curves to Ease, for some reason we have not yet discovered with this animation easeOutBack it does not Avanca

we still don’t know why the easeInOutBack animation didn’t work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.