Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
Flutter - Auto size text
Next article icon

Flutter - Auto size text

Last Updated : 04 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

An adaptive UI is an integral part of any application. As applications nowadays have to function on a wide range of devices ranging from tablets, PCs, and mobile with varying screen sizes. This is where the application needs to adjust itself according to the size of the screen irrespective of the size of the content of the application.

Flutter provides with an auto_size_text dependency that adapts the screen according to the screen size and manipulates itself to provide with adaptive user experience. The above dependency adjusts the size of the text in the application. In this article, we will explore the same dependency in detail by building a simple application.

Steps to implement auto_size_text in Flutter

Step 1 : Adding the Dependency

To add the dependency to the pubspec.yaml file,  add the auto_size_text to the flutter dependency as shown below:

dependencies:
auto_size_text: ^3.0.0

Now run the below command in terminal.

flutter pub get

Step 2 : Importing the Dependency

The dependency can be imported into the main.dart file as follows:

import 'package:auto_size_text/auto_size_text.dart';


Step 3 : Creating the App structure

Use the StatelessWidget to give a simple structure to the app as shown below:

Dart
class App extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       home: Scaffold(         appBar:AppBar(title: Text('GeeksForGeeks'),           backgroundColor: Colors.green,),          ),       ),     );   } } 


Step 4 : Adding a Sample text

A text inside the body of the application can be added inside a sizedBox as shown below:

Dart
          child: SizedBox(             width: 200.0,             height: 140.0,             child: AutoSizeText(               'Hello Geeks!. We will break this line into 3 lines !!',               style: TextStyle(fontSize: 30.0),               maxLines: 3,             ),           ), 

To know more about SizedBox in flutter refer this article: Flutter – SizedBox Widget


Complete Source Code(main.dart):

Dart
import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart';  void main() {   runApp(App()); }  class App extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       home: Scaffold(         appBar:AppBar(title: Text('GeeksForGeeks'),           backgroundColor: Colors.green,),          body: Center(           child: SizedBox(             width: 200.0,             height: 140.0,             child: AutoSizeText(               'Hello Geeks!. We will break this line into 3 lines !!',               style: TextStyle(fontSize: 30.0),               maxLines: 3,             ),           ),         ),       ),     );   } } 

Output:

autotext


If you wish to make the text fit in 2 lines instead of 3 line, make the below changes to the code.

main.dart:

Dart
import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart';  // Main function to run the app void main() {   runApp(MyApp()); }  // MyApp is a stateless widget class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       debugShowCheckedModeBanner: false,       home: Scaffold(         appBar: AppBar(           title: Text('GeeksForGeeks'),           backgroundColor: Colors.green,           foregroundColor: Colors.white,         ),         body: Center(           child: SizedBox(             width: 200.0,             height: 140.0,             child: AutoSizeText(               'Hello Geeks! We will break this line into 3 lines !!',               style: TextStyle(fontSize: 30.0),               maxLines: 2,             ),           ),         ),       ),     );   } } 

Output:

auto_text



Next Article
Flutter - Auto size text

D

ddeevviissaavviittaa
Improve
Article Tags :
  • Dart
  • Flutter
  • Android
  • Flutter
  • Flutter UI-components

Similar Reads

    Animated Text in Flutter
    Animations make the UI more interactive and enhance the user experience. There is no limitation of creativity when it comes to animations or making the application more interactive. In Flutter, we got an easy way to display Animated text. In this article, we will see how we can animate texts using a
    3 min read
    Flutter - Skeleton Text
    In Flutter, the skeleton_text library is used to easily implement skeleton text loading animation. Its main application in a flutter app is to assure its users that the servers are working but running slow, but the content will eventually load. It also enhances the User Interface if the user connect
    3 min read
    Flutter - Load Text Assets
    In Flutter, you can easily load text assets such as JSON files, configuration files, or plain text files into your app's memory at runtime. This allows you to access the data contained in these files and use it to populate your app's UI or perform other operations. To load text assets in Flutter, yo
    3 min read
    Flutter - Create 3D Text
    Flutter, developed by Google, has gained immense popularity among developers due to its flexibility and ease of use. With Flutter, we can create stunning user interfaces, including 3D elements. This tutorial will explore how to create 3D text in Flutter step by step using the text_3d library. A samp
    5 min read
    Flutter - Custom Widgets
    We create Custom Widgets when we want a custom look and feel to our app, and we know that there will be a repetition of a particular widget. We can create the custom widget in a new dart file with all the codes and defining the parameters that we need in the constructor. For more on how to split wid
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences