• Taha Tesser's avatar
    Add delete button support to `FilterChip` (#136645) · 6c3010e7
    Taha Tesser authored
    fixes [`FilterChip` should have `DeletableChipAttributes`/`trailing` to match Material 3 spec.](https://github.com/flutter/flutter/issues/135595)
    
    ### 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  MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: ThemeData(useMaterial3: true),
          home: const Example(),
        );
      }
    }
    
    class Example extends StatelessWidget {
      const Example({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const Text('FilterChip'),
                const SizedBox(height: 8),
                FilterChip(
                  avatar: const Icon(Icons.favorite_rounded),
                  label: const Text('FilterChip'),
                  selected: true,
                  showCheckmark: false,
                  onSelected: (bool value) {},
                  onDeleted: () {},
                  deleteButtonTooltipMessage: 'Delete Me!',
                ),
                const SizedBox(height: 16),
                FilterChip(
                  avatar: const Icon(Icons.favorite_rounded),
                  label: const Text('FilterChip'),
                  onSelected: (bool value) {},
                  onDeleted: () {},
                ),
                const SizedBox(height: 48),
                const Text('FilterChip.elevated'),
                const SizedBox(height: 8),
                FilterChip.elevated(
                  avatar: const Icon(Icons.favorite_rounded),
                  label: const Text('FilterChip'),
                  selected: true,
                  showCheckmark: false,
                  onSelected: (bool value) {},
                  onDeleted: () {},
                ),
                const SizedBox(height: 16),
                FilterChip.elevated(
                  avatar: const Icon(Icons.favorite_rounded),
                  label: const Text('FilterChip'),
                  onSelected: (bool value) {},
                  onDeleted: () {},
                ),
              ],
            ),
          ),
        );
      }
    }
    ```
    
    </details>
    
    ### Before
    
    Not possible to add delete button
    
    ### After 
    ![Screenshot 2023-10-16 at 17 56 51](https://github.com/flutter/flutter/assets/48603081/ad751ef9-c2bc-4184-ae5f-4d1017eff664)
    6c3010e7
filter_chip_test.dart 28.7 KB