Milad-Akarie / auto_route_library

Flutter route generator
MIT License
1.56k stars 394 forks source link

showDialog have unexpected padding at top when opning inside a CustomScrollView #1723

Open wer-mathurin opened 1 year ago

wer-mathurin commented 1 year ago
import 'package:auto_route/auto_route.dart';
import 'package:auto_route_dialog/app_router.dart';
import 'package:flutter/material.dart';

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

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

  final _appRouter = AppRouter();

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _appRouter.config(),
    );
  }
}

@RoutePage()
class BasePage extends StatelessWidget {
  const BasePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // return Scaffold(
    //   appBar: AppBar(title: const Text('Title')),
    //   body: const AutoRouter(),
    // );

    return const Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar(title: Text('Title')),
          SliverFillRemaining(child: AutoRouter())
        ],
      ),
    );
  }
}

@RoutePage()
class PageOne extends StatelessWidget {
  const PageOne({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: ElevatedButton(
        onPressed: () {
          showDialog(
            context: context,
            useRootNavigator: false,
            useSafeArea: true,
            builder: (context) => Dialog(
              insetPadding: const EdgeInsets.all(8),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  const SizedBox(height: 200),
                  const Text('Hi'),
                  const SizedBox(height: 200),
                  TextButton(
                      onPressed: () => context.router.pop(),
                      child: const Text('Close'))
                ],
              ),
            ),
          );
        },
        child: const Text('Open dialog'),
      ),
    );
  }
}

@RoutePage()
class PageTwo extends StatelessWidget {
  const PageTwo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const Center(
      child: Text('Page 2'),
    );
  }
}
Milad-Akarie commented 11 months ago

@wer-mathurin isn't in the size of SliverAppBar? if you want your dialog to take full screen you should set useRootNavigator to true..

wer-mathurin commented 11 months ago

@Milad-Akarie The idea of the provided code is to show that we have a different result if you use the custom scroll view compare that a basic scaffold and an appbar. ( commented code).

We do not want a full screen dialog since we want to have access to the appbar and/or bottom bar.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions