Skip to content

Checkbox and Chips side with MaterialStateBorderSide doesn't lerp in their theme #135136

@guidezpl

Description

@guidezpl

In the following, I would expect the side to lerp smoothly between red and blue, but it switches to a single pixel wide grey border instead.

af79f359-3e8a-48a8-91ac-9c6d72c9c9d3

import 'package:flutter/material.dart';

import 'package:flutter/scheduler.dart';

void main() {
  // Slow down time to see lerping.
  timeDilation = 5.0;
  runApp(const ThemeExtensionExampleApp());
}

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

  @override
  State<ThemeExtensionExampleApp> createState() =>
      _ThemeExtensionExampleAppState();
}

class _ThemeExtensionExampleAppState extends State<ThemeExtensionExampleApp> {
  bool isLightTheme = true;

  void toggleTheme() {
    setState(() => isLightTheme = !isLightTheme);
  }

  @override
  Widget build(BuildContext context) {
    final ColorScheme colorScheme = isLightTheme
        ? ColorScheme.fromSeed(seedColor: Colors.red)
        : ColorScheme.fromSeed(seedColor: Colors.blue);
    return MaterialApp(
      theme:
          ThemeData.from(colorScheme: colorScheme, useMaterial3: true).copyWith(
        checkboxTheme: CheckboxThemeData(
          side: MaterialStateBorderSide.resolveWith((states) {
            return BorderSide(
              color: colorScheme.primary,
              width: 4,
            );
          }),
        ),
      ),
      home: Home(
        isLightTheme: isLightTheme,
        toggleTheme: toggleTheme,
      ),
    );
  }
}

class Home extends StatelessWidget {
  const Home({
    super.key,
    required this.isLightTheme,
    required this.toggleTheme,
  });

  final bool isLightTheme;
  final void Function() toggleTheme;

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Checkbox(value: false, onChanged: (_) {}),
            const SizedBox(width: 50),
            IconButton(
              icon: const Icon(Icons.palette),
              tooltip: 'Toggle color',
        
              onPressed: toggleTheme,
            ),
          ],
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.found in release: 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions