How to determine if the user has modified the default font size in flutter mobile app?

This Article is posted by seven.srikanth at 11/16/2022 4:18:40 AM



You can determine if the user has modified the default font size in the flutter mobile app using MediaQuery textScaleFactor. 
Here is how the example works. 
Here is the complete code from main.dart file. 

import 'package:flutter/material.dart';
void main(List<String> args) {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @ override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: MyWidget(),
      ),
    );
  }
}
class MyWidget extends StatelessWidget {
  const MyWidget({
    super.key,
  });
  @ override
  Widget build(BuildContext context) {
    var fontScaling = MediaQuery.of(context).textScaleFactor;
    return Center(
      child: Text(
        '$fontScaling ',
        style: const TextStyle(fontSize: 50.0),
      ),
    );
  }
}
Hope this is useful to you.
Thanks,
Srikanth

Tags: textScaleFactor








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com