Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import 'dart:math' as math;
  2.  
  3. import 'package:flutter/widgets.dart';
  4.  
  5. class TextScaleFactor extends StatelessWidget {
  6. const TextScaleFactor({
  7. Key key,
  8. @required this.child,
  9. this.min = 1,
  10. this.max,
  11. }) : super(key: key);
  12.  
  13. final Widget child;
  14. final double min;
  15. final double max;
  16.  
  17. @override
  18. Widget build(BuildContext context) {
  19. final mediaQuery = MediaQuery.of(context);
  20. if (mediaQuery == null) {
  21. assert(false, 'TextScaleFactor should be placed inside of MediaQuery');
  22. return child;
  23. }
  24. final textScaleFactor = mediaQuery.textScaleFactor ?? 1;
  25. final adjustedFactor =
  26. math.min(math.max(min ?? 0, textScaleFactor), max ?? double.infinity);
  27. return MediaQuery(
  28. data: mediaQuery.copyWith(textScaleFactor: adjustedFactor),
  29. child: child,
  30. );
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement