forked from zulip/zulip-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: Set letter spacing to 1% in buttons
TextTheme.labelLarge is the default label style in all the various Material buttons; see: [ElevatedButton.defaultStyleOf], [FilledButton.defaultStyleOf], [MenuItemButton.defaultStyleOf], [MenuItemButton.defaultStyleOf], [OutlinedButton.defaultStyleOf], `defaults` in [SegmentedButton.build], [TextButton.defaultStyleOf] . Since our buttons are all Material buttons, changing this will effectively "set letter spacing to 1% in buttons", which is zulip#548. (...Actually, I guess there's one kind of button that's not a Material button: reaction chips in the message list. So, adjust those separately, also in this commit.) Greg mentioned, when suggesting this approach, > In principle that has a slightly broader effect than specified in > zulip#548, in that it affects any other Material widgets that use the > `labelLarge` text style. But fundamentally those are widgets that > the Material designers intended to have a similar text style to > that of buttons (even though they're not called "buttons"), so > it's likely that that'll be the right answer anyway. > If we end up with such a widget where Vlad wants a different > spacing, we can address that then… and I think it's fairly likely > that in that case he'd want something that wasn't the Material > widget in any event. Which makes sense and works for me. Fixes: zulip#548
- Loading branch information
1 parent
af20651
commit d882f50
Showing
6 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/rendering.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/widgets/text.dart'; | ||
import 'package:zulip/widgets/theme.dart'; | ||
|
||
import '../flutter_checks.dart'; | ||
|
||
void main() { | ||
group('button text size and letter spacing', () { | ||
const buttonText = 'Zulip'; | ||
|
||
Future<void> doCheck( | ||
String description, { | ||
required Widget button, | ||
double? ambientTextScaleFactor, | ||
}) async { | ||
testWidgets(description, (WidgetTester tester) async { | ||
if (ambientTextScaleFactor != null) { | ||
tester.platformDispatcher.textScaleFactorTestValue = ambientTextScaleFactor; | ||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); | ||
} | ||
late final double expectedFontSize; | ||
late final double expectedLetterSpacing; | ||
await tester.pumpWidget( | ||
Builder(builder: (context) => MaterialApp( | ||
theme: zulipThemeData(context), | ||
home: Builder(builder: (context) { | ||
expectedFontSize = Theme.of(context).textTheme.labelLarge!.fontSize!; | ||
expectedLetterSpacing = proportionalLetterSpacing(context, | ||
0.01, baseFontSize: expectedFontSize); | ||
return button; | ||
})))); | ||
|
||
final text = tester.renderObject<RenderParagraph>(find.text(buttonText)).text; | ||
check(text.style!) | ||
..fontSize.equals(expectedFontSize) | ||
..letterSpacing.equals(expectedLetterSpacing); | ||
}); | ||
} | ||
|
||
doCheck('with device text size adjusted', | ||
ambientTextScaleFactor: 2.0, | ||
button: ElevatedButton(onPressed: () {}, child: const Text(buttonText))); | ||
|
||
doCheck('ElevatedButton', | ||
button: ElevatedButton(onPressed: () {}, child: const Text(buttonText))); | ||
|
||
doCheck('FilledButton', | ||
button: FilledButton(onPressed: () {}, child: const Text(buttonText))); | ||
|
||
// IconButton can't have text; skip | ||
|
||
doCheck('MenuItemButton', | ||
button: MenuItemButton(onPressed: () {}, child: const Text(buttonText))); | ||
|
||
doCheck('SubmenuButton', | ||
button: const SubmenuButton(menuChildren: [], child: Text(buttonText))); | ||
|
||
doCheck('OutlinedButton', | ||
button: OutlinedButton(onPressed: () {}, child: const Text(buttonText))); | ||
|
||
doCheck('SegmentedButton', | ||
button: SegmentedButton(selected: const {1}, | ||
segments: const [ButtonSegment(value: 1, label: Text(buttonText))])); | ||
|
||
doCheck('TextButton', | ||
button: TextButton(onPressed: () {}, child: const Text(buttonText))); | ||
}); | ||
} |