flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.17k stars 26.65k forks source link

Introduce `TabBar.textScaler` for tab label upper text scale limit #147232

Closed TahaTesser closed 1 week ago

TahaTesser commented 3 weeks ago

fixes Tab is hardcoding the height of the icons and the text

Description

This PR introduces TabBar.textScaler to provide upper text scale limit for tab label.

Code sample

expand to view the code sample ```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, home: MediaQuery( data: const MediaQueryData(textScaler: TextScaler.linear(3.0)), child: DefaultTabController( length: 3, child: Scaffold( appBar: AppBar( title: const Text('Sample'), bottom: const TabBar( textScaler: TextScaler.linear(2.0), tabs: [ Tab(text: 'Tab 1'), Tab(text: 'Tab 2'), Tab(text: 'Tab 3'), ], ), ), floatingActionButton: Builder(builder: (BuildContext context) { return FloatingActionButton( onPressed: () { print(MediaQuery.textScalerOf(context)); }, child: const Icon(Icons.add), ); }), ), ), ), ); } } ```

Without TabBar.textScaler

Screenshot 2024-04-30 at 13 46 10

With TabBar.textScaler

              bottom: const TabBar(
                textScaler: TextScaler.linear(2.0),
                tabs: <Widget>[
                  Tab(text: 'Tab 1'),
                  Tab(text: 'Tab 2'),
                  Tab(text: 'Tab 3'),
                ],
              ),

Screenshot 2024-04-30 at 14 04 22

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

TahaTesser commented 2 weeks ago

I checked the Google testing failures, and they appear to be legitimate, There are existing customers that expect to be able to create the before image in this PR.

@TahaTesser maybe there is a way we can make this opt-in?

Added TabBar.textScaler which can override the text scale for tab label, optionally. This ensures the existing tests are not effected.

EditableText and SelectableText also contain parameter to override their text scale.

Updated the PR and description as well. Please let me know what do you think.

TahaTesser commented 1 week ago

@Piinks Thanks for review! Rebasing just in case. :)