Skip to content

Instantly share code, notes, and snippets.

@jeroen-meijer
Last active June 2, 2022 12:29
Show Gist options
  • Save jeroen-meijer/5288d8d540e71b02c72f4b53822792b3 to your computer and use it in GitHub Desktop.
Save jeroen-meijer/5288d8d540e71b02c72f4b53822792b3 to your computer and use it in GitHub Desktop.
Alchemist button styling issue
import 'package:alchemist/alchemist.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
final theme = ThemeData(
// In this configuration, the bug occurs.
//
// It does not occur if:
// - no textButtonTheme is provided
// - the provided TextButtonThemeData is empty
// - the TextButton.styleFrom call is called with no textStyle argument
// - a fontFamily is provided to the TextStyle, such as Roboto
//
// Creating an empty TextStyle and providing it as done below causes the bug.
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
textStyle: const TextStyle(
// fontFamily: 'Roboto',
),
),
),
);
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('TextButton', () {
AlchemistConfig.runWithConfig(
config: AlchemistConfig(
ciGoldensConfig: const CiGoldensConfig(enabled: false),
platformGoldensConfig: PlatformGoldensConfig(
theme: theme,
),
),
run: () {
goldenTest(
'renders correctly',
fileName: 'text_button',
builder: () {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Builder(
builder: (context) {
print(
'style for text: '
'${DefaultTextStyle.of(context).style}',
);
return const Text('Regular Text');
},
),
TextButton(
onPressed: () {},
child: Builder(
builder: (context) {
print(
'style for button: '
'${DefaultTextStyle.of(context).style}',
);
return const Text('Button Text');
},
),
),
],
);
},
);
},
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment