The 17 most useful Flutter widgets I wish I’d ​​known about sooner

- Andrés Cruz - ES En español

The 17 most useful Flutter widgets I wish I’d ​​known about sooner

Learning a new framework can be overwhelming, especially when you do not know where to start. In Flutter, one of the most important concepts is widgets, since everything—absolutely everything—is a widget. In this article, I will show you the most practical and useful Flutter widgets I wish I had known from the beginning, so you do not have to learn them the hard way.

Spacer

Spacer creates a flexible empty space that takes up any remaining room between widgets inside a Flex container, such as Row or Column. Its main advantage is that you can control the space proportion using the flex property: the higher the value, the greater the relative space it occupies. This makes it ideal for distributing elements dynamically without needing fixed padding values.

Row(
        children: const <Widget>[
          Text('Begin'),
          Spacer(), // Defaults to flex: 1
          Text('Middle'),
          // This Spacer takes up twice as much space as the previous one
          Spacer(flex: 2),
          Text('End'),
        ],
      ),

TextButton.icon

This widget eliminates the need to manually wrap a Row to place an icon next to text inside a button. You only need to provide the icon and label properties, and Flutter handles the rest. It is the cleanest and most semantic way to create buttons with icons in Material Design.

TextButton.icon(
              onPressed: () {},
              icon: Icon(Icons.home),
              label: Text('Home'),
            ),

Wrap

Wrap displays its child widgets horizontally or vertically depending on the value of the direction property. Unlike Row or Column, when it runs out of space it automatically moves to the next line or column, making it an excellent alternative to GridView when you need a layout that adapts naturally to different screen sizes without complex configurations.

Wrap(
              direction: Axis.horizontal,
              alignment: WrapAlignment.start,
              spacing: 2.0,   // horizontal space between widgets
              runSpacing: 3.0, // vertical space between lines
              children: [],
            )

AnimatedSwitcher

AnimatedSwitcher animates the transition between one widget and another, giving your app a much smoother and more professional feel. One critical detail: always add a unique key to the child widget (for example, a ValueKey); otherwise, Flutter will not detect the change and the animation will not run. You can customize the animation type using the transitionBuilder parameter.

AnimatedSwitcher(
           child: Text(
             '$_count',
             // This key makes AnimatedSwitcher treat each change
             // as a new widget and trigger the animation
             key: ValueKey<int>(_count),
           ),
           duration: Duration(milliseconds: 200),
           transitionBuilder: (Widget child, Animation<double> animation) {
             return ScaleTransition(scale: animation, child: child);
           },
         )

SafeArea

SafeArea adds automatic padding to its content to ensure your interface is not hidden behind operating system elements such as the status bar, notch, or gesture navigation bars. It is especially important on modern devices with punch-hole or rounded-corner displays. Always use it as the root container of your screens to avoid surprises across different devices.

SafeArea(child: Container())

RefreshIndicator

RefreshIndicator wraps scrollable widgets like ListView and detects when the user performs a pull-to-refresh gesture. When this happens, it displays an animated circular indicator and executes a Future function to reload the content. It is the standard pattern in mobile apps for updating data lists, and your users already know how it works intuitively.

RefreshIndicator(
  child: ListView(),
  onRefresh: () async {
    // Logic to reload data
  },
),

RichText

RichText lets you display text with multiple styles within the same sentence or paragraph. It works through TextSpan, which acts as a text node to which you can assign its own independent TextStyle. It is ideal for mixed text with bold formatting, colors, or inline clickable links without needing to stack multiple Text widgets.

RichText(
  text: TextSpan(
    text: 'Hello ',
    style: DefaultTextStyle.of(context).style,
    children: const <TextSpan>[
      TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
      TextSpan(text: ' world!'),
    ],
  ),
)

Transform

Transform takes your animations and visual effects to another level. It lets you apply geometric transformations to any widget: rotations, scaling, translations, and even 3D transformations and skew effects. For the most common cases, it provides named constructors such as Transform.rotate(), Transform.scale(), and Transform.translate(), simplifying usage without working directly with matrices.

Container(
  color: Colors.black,
  child: Transform(
    alignment: Alignment.topRight,
    transform: Matrix4.skewY(0.3)..rotateZ(-math.pi / 12.0),
    child: Container(
      padding: const EdgeInsets.all(8.0),
      color: const Color(0xFFE8581C),
      child: const Text('Hello there!'),
    ),
  ),
)

InteractiveViewer

InteractiveViewer is the easiest way to add pinch-to-zoom, panning, and dragging capabilities to any widget. You can control scale limits with minScale and maxScale, as well as define panning margins with boundaryMargin. It is ideal for image galleries, maps, or any content the user needs to explore in detail.

InteractiveViewer(
       boundaryMargin: const EdgeInsets.all(20.0),
       minScale: 0.1,
       maxScale: 1.6,
       child: Container(
         decoration: const BoxDecoration(
           gradient: LinearGradient(
             begin: Alignment.topCenter,
             end: Alignment.bottomCenter,
             colors: <Color>[Colors.orange, Colors.red],
             stops: <double>[0.0, 1.0],
           ),
         ),
       ),
     ),

Flow

Flow is one of those widgets that is much easier to understand by seeing it in action than by reading its definition. It leverages matrix transformations to create highly customized and efficient layout animations, repainting only the elements that change. It is more complex to configure than other layout widgets, but when you need something out of the ordinary, it is well worth exploring. You can check the official Flow widget documentation to see advanced examples.

Chip

Chip is a simple yet versatile widget for displaying compact information and tags in a visual, organized way. It includes specialized variants depending on the use case: InputChip for chips the user can delete, ChoiceChip for single selection, FilterChip for multiple active filters, and ActionChip for triggering actions. They are very common on filter screens, category tags, and option selectors.

Chip(
  avatar: CircleAvatar(
    backgroundColor: Colors.grey.shade800,
    child: const Text('AB'),
  ),
  label: const Text('Aaron Burr'),
)

EndDrawer

EndDrawer is a side panel that slides out from the right side of the screen, unlike the traditional Drawer that opens from the left. Although frequently used for navigation, one of its most practical uses is as an advanced filter panel: it appears contextually when the user needs it without taking up permanent screen space. Simply assign the widget to the endDrawer property of a Scaffold.

class EndDrawerScreen extends StatefulWidget {
  const EndDrawerScreen({Key? key}) : super(key: key);

  @override
  _EndDrawerScreenState createState() => _EndDrawerScreenState();
}

class _EndDrawerScreenState extends State<EndDrawerScreen> {
  late ThemeData theme;

  GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: scaffoldKey,
      appBar: AppBar(
        title: const Text("End Drawer"),
      ),
      endDrawer: endDrawer(),
      resizeToAvoidBottomInset: false,
      body: const Center(child: Text("End Drawer Screen")),
    );
  }

  Widget endDrawer() {
    return SafeArea(
      child: Container(
        margin: const EdgeInsets.all(16),
        width: 300,
        decoration: const BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(8)),
          color: Colors.green,
        ),
        child: Drawer(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
                color: Colors.lightBlue,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    const Center(
                      child: Text(
                        "Filter",
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 20,
                        ),
                      ),
                    ),
                    IconButton(
                      onPressed: () {
                        Navigator.pop(context);
                      },
                      icon: const Icon(
                        Icons.cancel,
                        color: Colors.white,
                      ),
                    )
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.all(8),
                child: const Text(
                  "Select your category",
                  style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
                ),
              ),
              Container(
                padding: EdgeInsets.all(8),
                child: Wrap(
                  spacing: 4,
                  runSpacing: 4,
                  children: categories(),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  List<Widget> categories() {
    List<String> typesList =
        List<String>.generate(10, (index) => "Category $index");

    List<Widget> categories = [];
    for (var item in typesList) {
      categories.add(Container(
        decoration: BoxDecoration(
          borderRadius: const BorderRadius.all(Radius.circular(12)),
          color: Colors.grey.shade300,
        ),
        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
        child: Text(item),
      ));
    }
    return categories;
  }
}

Loading Button

Personally, I prefer an animated loading button over the classic CircularProgressIndicator because it visually communicates three states: loading, success, or error. This also prevents the user from tapping the button multiple times while an operation is in progress—something you cannot easily guarantee with a floating progress indicator. For this, you can use the rounded_loading_button package, which provides the RoundedLoadingButton widget and its RoundedLoadingButtonController.

class CustomLoadingButton extends StatelessWidget {
  final RoundedLoadingButtonController controller;
  final VoidCallback? onPressed;
  final EdgeInsetsGeometry? padding;
  final double? elevation;
  final double borderRadiusAll;
  final Color? backgroundColor;
  final Color? successColor;
  final Color? errorColor;
  final Color? splashColor;
  final Widget child;
  final double width;
  final double height;

  const CustomLoadingButton({
    Key? key,
    required this.controller,
    this.onPressed,
    required this.child,
    this.padding,
    this.borderRadiusAll = 0,
    this.backgroundColor = Colors.green,
    this.successColor = Colors.green,
    this.errorColor = Colors.red,
    this.elevation = 4,
    this.splashColor,
    this.height = 35,
    this.width = 300,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return RoundedLoadingButton(
      color: backgroundColor,
      successColor: successColor,
      errorColor: errorColor,
      controller: controller,
      onPressed: onPressed,
      valueColor: Colors.white,
      borderRadius: borderRadiusAll,
      child: child,
      height: height,
      width: width,
    );
  }
}

// Usage example with form validation
RoundedLoadingButtonController btnController = RoundedLoadingButtonController();
TextEditingController textEditingController = TextEditingController();
final formKey = GlobalKey<FormState>();

@override
Widget build(BuildContext context) {
  return Container(
    padding: EdgeInsets.all(16),
    child: Form(
      key: formKey,
      onChanged: () {
        if (btnController.currentState == ButtonState.success ||
            btnController.currentState == ButtonState.error) {
          btnController.reset();
        }
        formKey.currentState!.validate();
      },
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          TextFormField(
            controller: textEditingController,
            decoration: InputDecoration(
              labelText: "Add your number",
            ),
            validator: (value) {
              if (value != null && value.isNotEmpty) {
                if (RegExp(r'^[a-z]+$').hasMatch(value)) {
                  return "Just numbers allowed";
                }
                return null;
              } else {
                return "Please enter your number";
              }
            },
          ),
          SizedBox(height: 16),
          Center(
            child: RoundedLoadingButton(
              controller: btnController,
              onPressed: () {
                Future.delayed(Duration(seconds: 1)).then((value) {
                  if (formKey.currentState!.validate()) {
                    btnController.success();
                  } else {
                    btnController.error();
                  }
                });
              },
              color: Colors.blue,
              child: Text("Add"),
            ),
          ),
        ],
      ),
    ),
  );
}

Stepper

Stepper is a Material Design widget that displays user progress through a sequence of numbered steps. It is particularly useful in multi-stage forms where one step depends on completing the previous one, or where you need to guide the user in an orderly way through a complex process such as checkout, registration, or onboarding. It can be oriented either vertical or horizontal using the type property.

showModalBottomSheet

A Modal Bottom Sheet is an elegant alternative to traditional menus and dialog boxes. By sliding up from the bottom of the screen, it blocks interaction with the rest of the app until dismissed, making it ideal for confirming actions or presenting additional options without redirecting the user to another screen. It is invoked programmatically with the showModalBottomSheet() function and accepts any widget as its content.

class BottomSheetScreen extends StatefulWidget {
  const BottomSheetScreen({Key? key}) : super(key: key);

  @override
  State<BottomSheetScreen> createState() => _BottomSheetScreenState();
}

class _BottomSheetScreenState extends State<BottomSheetScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Modal Bottom Sheet'),
      ),
      body: Container(
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text("MODAL BOTTOM SHEET"),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                showModalBottomSheet(
                  context: context,
                  builder: (context) {
                    return Column(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        ListTile(
                          leading: const Icon(Icons.copy),
                          title: const Text('Copy'),
                          onTap: () {
                            Navigator.pop(context);
                          },
                        ),
                        ListTile(
                          leading: const Icon(Icons.save),
                          title: const Text('Save'),
                          onTap: () {
                            Navigator.pop(context);
                          },
                        ),
                        ListTile(
                          leading: const Icon(Icons.share),
                          title: const Text('Share'),
                          onTap: () {
                            Navigator.pop(context);
                          },
                        ),
                      ],
                    );
                  },
                );
              },
              child: const Text('Click Me'),
            ),
          ],
        ),
      ),
    );
  }
}

Tooltip

Tooltip displays a descriptive text label when long-pressing a widget, significantly improving your app's accessibility. Screen readers can vocalize this text, making your icons and buttons understandable to visually impaired users. Keep in mind that Tooltip is meant for brief, descriptive text; it is not the right place to display images or complex information.

Tooltip(
  message: "Add new item",
  child: Icon(Icons.add_circle_rounded, size: 32, color: Colors.blue),
),

Slide Action

Slide Action is an interaction pattern that asks the user to drag an element to confirm an important action, such as deleting a record, making a payment, or confirming a critical operation. By requiring a deliberate gesture instead of a simple tap, it drastically reduces accidental errors. You can implement it with the flutter_slidable package or with the RichText widget combined with gesture recognizers for simpler actions.

// Example using RichText for styled action text
RichText(
  text: const TextSpan(
    text: 'Don\'t have an account yet? ',
    style: TextStyle(
      color: Colors.black,
      fontSize: 18,
    ),
    children: [
      TextSpan(
        text: 'Sign',
        style: TextStyle(
          color: Colors.blue,
          fontSize: 18,
          decoration: TextDecoration.underline,
          fontWeight: FontWeight.w800,
        ),
      ),
      TextSpan(text: ' '),
      TextSpan(
        text: 'Up',
        style: TextStyle(
          color: Colors.red,
          fontSize: 18,
          decoration: TextDecoration.underline,
          fontWeight: FontWeight.w800,
        ),
      ),
    ],
  ),
)

Discover the most useful and practical Flutter widgets, complete with real-world code examples. From Spacer and Wrap to AnimatedSwitcher and Chip—this is the essential guide for any Flutter developer.


Únete a la comunidad de desarrolladores que han decidido dejar de picar código y empezar a construir productos reales. Recibe mis mejores trucos de arquitectura cada semana:

I agree to receive announcements of interest about this Blog.