2

I'm using a PageView to create sliding transitions between multiple pages containing a basic RaisedButton.

However, the button is not clickable during the transition. Instead, when the screen is taped, it cancels or terminates the transition, but a second click is required afterward.

My app looks like this:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final controller = PageController();

    return MaterialApp(
      title: "MyApp",
      initialRoute: "/",
      routes: {
        "/": (context) => PageView(
              controller: controller,
              children: List.generate(100, (_) => MyPage(controller)),
            ),
      },
    );
  }
}

My page looks like this:

class MyPage extends StatelessWidget {
  final PageController controller;

  MyPage(this.controller);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        RaisedButton(
          onPressed: () {
            controller.nextPage(
              duration: Duration(milliseconds: 5000),
              curve: Curves.ease,
            );
          },
          child: Text("Go to next page"),
        ),
        SizedBox(
          width: 200,
          height: 200,
          child: RaisedButton(
            onPressed: () => debugPrint("Button clicked!"),
            child: Text("Click me"),
          ),
        )
      ],
    );
  }
}

Is there a way to somehow "force" the button to be pressed even if a transition from one page to another is in progress?

Delgan
  • 18,571
  • 11
  • 90
  • 141
  • I believe you can't interact with the widget while the animation is running. It would help if you explained what you is the end use you want to achieve. – J. S. Dec 21 '19 at 22:19
  • @JoãoSoares Being able to click on a widget during a PageView transition is basically all that I want to achieve. Sometimes, I click on a button while the page is transitioning, but it has no effect (because of the transition), and I think it will bother the users. – Delgan Dec 22 '19 at 07:47
  • Did you find a solution to this? – Martin May 11 '21 at 17:01
  • @Mitch No, I didn't. I'm no longer using `PageView` anyway. – Delgan May 11 '21 at 17:27

0 Answers0