mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Fixes https://github.com/flutter/flutter/issues/143482 This brings in the gallery more or less as is: * Removed localizations * Ensure tests still run (locally verified, will switch CI later). * Removed deferred components * Fixup pubspec
43 lines
1.7 KiB
Dart
43 lines
1.7 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../data/gallery_options.dart';
|
|
|
|
double _textScaleFactor(BuildContext context) {
|
|
return GalleryOptions.of(context).textScaleFactor(context);
|
|
}
|
|
|
|
// When text is larger, this factor becomes larger, but at half the rate.
|
|
//
|
|
// | Text scaling | Text scale factor | reducedTextScale(context) |
|
|
// |--------------|-------------------|---------------------------|
|
|
// | Small | 0.8 | 1.0 |
|
|
// | Normal | 1.0 | 1.0 |
|
|
// | Large | 2.0 | 1.5 |
|
|
// | Huge | 3.0 | 2.0 |
|
|
|
|
double reducedTextScale(BuildContext context) {
|
|
final double textScaleFactor = _textScaleFactor(context);
|
|
return textScaleFactor >= 1 ? (1 + textScaleFactor) / 2 : 1;
|
|
}
|
|
|
|
// When text is larger, this factor becomes larger at the same rate.
|
|
// But when text is smaller, this factor stays at 1.
|
|
//
|
|
// | Text scaling | Text scale factor | cappedTextScale(context) |
|
|
// |--------------|-------------------|---------------------------|
|
|
// | Small | 0.8 | 1.0 |
|
|
// | Normal | 1.0 | 1.0 |
|
|
// | Large | 2.0 | 2.0 |
|
|
// | Huge | 3.0 | 3.0 |
|
|
|
|
double cappedTextScale(BuildContext context) {
|
|
final double textScaleFactor = _textScaleFactor(context);
|
|
return max(textScaleFactor, 1);
|
|
}
|