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
68b2f15
commit 71949f1
Showing
6 changed files
with
103 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,78 @@ | ||
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', () { | ||
Future<void> doCheck( | ||
String description, { | ||
required Widget Function(BuildContext context, String text) buttonBuilder, | ||
double? ambientTextScaleFactor, | ||
}) async { | ||
testWidgets(description, (WidgetTester tester) async { | ||
if (ambientTextScaleFactor != null) { | ||
tester.platformDispatcher.textScaleFactorTestValue = ambientTextScaleFactor; | ||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); | ||
} | ||
const buttonText = 'Zulip'; | ||
double? expectedFontSize; | ||
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 Builder(builder: (context) => | ||
buttonBuilder(context, buttonText)); | ||
})))); | ||
|
||
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, | ||
buttonBuilder: (context, text) => ElevatedButton(onPressed: () {}, | ||
child: Text(text))); | ||
|
||
doCheck('ElevatedButton', | ||
buttonBuilder: (context, text) => ElevatedButton(onPressed: () {}, | ||
child: Text(text))); | ||
|
||
doCheck('FilledButton', | ||
buttonBuilder: (context, text) => FilledButton(onPressed: () {}, | ||
child: Text(text))); | ||
|
||
// IconButton can't have text; skip | ||
|
||
doCheck('MenuItemButton', | ||
buttonBuilder: (context, text) => MenuItemButton(onPressed: () {}, | ||
child: Text(text))); | ||
|
||
doCheck('SubmenuButton', | ||
buttonBuilder: (context, text) => SubmenuButton(menuChildren: const [], | ||
child: Text(text))); | ||
|
||
doCheck('OutlinedButton', | ||
buttonBuilder: (context, text) => OutlinedButton(onPressed: () {}, | ||
child: Text(text))); | ||
|
||
doCheck('SegmentedButton', | ||
buttonBuilder: (context, text) => SegmentedButton(selected: const {1}, | ||
segments: [ButtonSegment(value: 1, label: Text(text))])); | ||
|
||
doCheck('TextButton', | ||
buttonBuilder: (context, text) => TextButton(onPressed: () {}, | ||
child: Text(text))); | ||
}); | ||
} |