No Directionality widget found

No Directionality widget found.

Quick Answer

A widget that needs text direction has no Directionality ancestor.

Why This Happens

In Flutter, widgets like Text, RichText, and others need to know the text direction (LTR or RTL). MaterialApp provides this automatically. If you use these widgets without a MaterialApp or Directionality ancestor (common in tests), this error occurs.

The Problem

// In a widget test without MaterialApp:
await tester.pumpWidget(Text('Hello')); // No Directionality!

The Fix

// Wrap in MaterialApp or Directionality:
await tester.pumpWidget(
  MaterialApp(home: Scaffold(body: Text('Hello'))),
);

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error: No Directionality widget found. A text-related widget has no text direction context.

  2. 2

    Find the cause

    Check if the widget is used without a MaterialApp ancestor, especially in widget tests.

  3. 3

    Apply the fix

    Wrap the widget in MaterialApp or Directionality(textDirection: TextDirection.ltr, child: ...).

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free