• Taha Tesser's avatar
    `CalendarDatePicker` doesn't announce selected date on desktop (#143583) · 5d2353c1
    Taha Tesser authored
    fixes [Screen reader is not announcing the selected date as selected on DatePicker](https://github.com/flutter/flutter/issues/143439)
    
    ### Descriptions
    - This fixes an issue where `CalendarDatePicker` doesn't announce selected date on desktop.
    - Add semantic label to describe the selected date is indeed "Selected".
    
    ### Code sample
    
    <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(
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key, required this.title});
    
      final String title;
    
      @override
      MyHomePageState createState() => MyHomePageState();
    }
    
    class MyHomePageState extends State<MyHomePage> {
      void _showDatePicker() async {
        await showDatePicker(
          context: context,
          initialDate: DateTime.now(),
          firstDate: DateTime(1900),
          lastDate: DateTime(2200),
        );
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title,
                style: const TextStyle(fontFamily: 'ProductSans')),
          ),
          body: const Center(
            child: Text('Click the button to show date picker.'),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: _showDatePicker,
            tooltip: 'Show date picker',
            child: const Icon(Icons.edit_calendar),
          ),
        );
      }
    }
    
    // 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(
    //       debugShowCheckedModeBanner: false,
    //       home: Scaffold(
    //         body: Center(
    //           child: CalendarDatePicker(
    //             initialDate: DateTime.now(),
    //             firstDate: DateTime(2020),
    //             lastDate: DateTime(2050),
    //             onDateChanged: (date) {
    //               print(date);
    //             },
    //           ),
    //         ),
    //       ),
    //     );
    //   }
    // }
    ```
    
    </details>
    
    ### Before
    
    https://github.com/flutter/flutter/assets/48603081/c82e1f15-f067-4865-8a5a-1f3c0c8d91da
    
    ### After
    
    https://github.com/flutter/flutter/assets/48603081/193d9e26-df9e-4d89-97ce-265c3d564607
    5d2353c1