• Taha Tesser's avatar
    Fix `DatePickerDialog` & `DateRangePickerDialog` overflow when resized from... · a0943e65
    Taha Tesser authored
    Fix  `DatePickerDialog` & `DateRangePickerDialog` overflow when resized from landscape to portrait (#133327)
    
    fixes [resize window with a `showDateRangePicker` will make RenderFlex overflowed error](https://github.com/flutter/flutter/issues/131989)
    
    ### Description
    - This fixes  `DatePickerDialog` & `DateRangePickerDialog` overflow error when resized from landscape to portrait.
    - Added tests that check these two widgets from landscape to portrait for no overflow errors.
    
    <details
    <summary>expand to view the code sample</summary> 
    
    ```dart
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Example(),
        );
      }
    }
    
    class Example extends StatefulWidget {
      const Example({super.key});
    
      @override
      State<Example> createState() => _ExampleState();
    }
    
    class _ExampleState extends State<Example> {
      bool _portait = false;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('DatePicker & DateRangePicker'),
          ),
          body: MediaQuery(
            data: MediaQuery.of(context).copyWith(
              size: _portait ? const Size(400, 800) : const Size(800, 400),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                DatePickerDialog(
                  initialDate: DateTime.now(),
                  firstDate: DateTime(2020),
                  lastDate: DateTime(2030),
                  initialEntryMode: DatePickerEntryMode.inputOnly,
                ),
                DateRangePickerDialog(
                  currentDate: DateTime.now(),
                  firstDate: DateTime(2020),
                  lastDate: DateTime(2030),
                  initialEntryMode: DatePickerEntryMode.inputOnly,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: () {
              setState(() {
                _portait = !_portait;
              });
            },
            child: const Icon(Icons.refresh),
          ),
        );
      }
    }
    
    ```
    
    </details>
    
    ### Before
    
    https://github.com/flutter/flutter/assets/48603081/81387cbb-cdcf-42bd-b4f8-b7a08317c955
    
    ### After
    
    https://github.com/flutter/flutter/assets/48603081/36d28ea9-cfed-48ad-90f5-0459755e08c0
    a0943e65
Name
Last commit
Last update
..
animation Loading commit data...
cupertino Loading commit data...
dart Loading commit data...
examples Loading commit data...
foundation Loading commit data...
gestures Loading commit data...
harness Loading commit data...
material Loading commit data...
painting Loading commit data...
physics Loading commit data...
rendering Loading commit data...
scheduler Loading commit data...
semantics Loading commit data...
services Loading commit data...
widgets Loading commit data...
_goldens_io.dart Loading commit data...
_goldens_web.dart Loading commit data...
analysis_options.yaml Loading commit data...
flutter_test_config.dart Loading commit data...
image_data.dart Loading commit data...