Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AlwaysFillViewportPageView and use the original PageView with OverflowBox #34

Open
fujidaiti opened this issue May 22, 2023 · 1 comment
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@fujidaiti
Copy link
Owner

fujidaiti commented May 22, 2023

I fond that AlwaysFillViewportPageView widget can be replaced with the original PageView with OverflowBox as follows. It's much more simpler than the current implementation and doesn't require copying and pasting the original source code of PageView. It should be also possible to rewrite the logic of overshoot effect using OverflowBox.

https://api.flutter.dev/flutter/widgets/OverflowBox-class.html

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(useMaterial3: true),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  static const viewportFraction = 0.8;
  final controller = PageController(
    viewportFraction: viewportFraction,
  );

  @override
  Widget build(BuildContext context) {
    final colors = [
      Colors.red,
      Colors.yellow,
      Colors.green,
      Colors.blue,
    ];
    return Scaffold(
      body: LayoutBuilder(
        builder: (context, constraints) {
          return PageView.builder(
            controller: controller,
            itemBuilder: (context, page) {
              return Transform.scale(
                scale: viewportFraction,
                child: OverflowBox(
                  minWidth: constraints.minWidth,
                  maxWidth: constraints.maxWidth,
                  minHeight: constraints.minHeight,
                  maxHeight: constraints.maxHeight,
                  child: ColoredBox(
                    color: colors[page % colors.length].withOpacity(0.7),
                    child: const Placeholder(),
                  ),
                ),
              );
            },
          );
        },
      ),
    );
  }
}

The result:

Simulator Screen Recording - iPhone 14 Pro - 2023-05-22 at 14 00 12

@fujidaiti fujidaiti added the enhancement New feature or request label May 22, 2023
@fujidaiti fujidaiti assigned fujidaiti and unassigned fujidaiti May 22, 2023
@fujidaiti fujidaiti added the wontfix This will not be worked on label May 26, 2023
@fujidaiti
Copy link
Owner Author

fujidaiti commented May 26, 2023

Basically it works, but there is a hit test problem where even if the size of an overflowbox is larger than its parent, the clickable area of the box is clipped at the parent's boundary. This is an issue when creating the box that overflows the page boundary for the overshoot effect.

@fujidaiti fujidaiti closed this as not planned Won't fix, can't repro, duplicate, stale Jun 11, 2023
@fujidaiti fujidaiti reopened this Jun 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant