FormatException: Invalid number

FormatException: Invalid radix-10 number (at character 1)

Quick Answer

You tried to parse a string that is not a valid number.

Why This Happens

In Dart, int.parse() and double.parse() throw FormatException when the input string is not a valid number. This commonly happens with user input or API data that contains unexpected characters. Use tryParse() for safe parsing that returns null instead of throwing.

The Problem

final input = 'abc';
final number = int.parse(input); // FormatException!

The Fix

final input = 'abc';
final number = int.tryParse(input) ?? 0;

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the FormatException message to see which string value could not be parsed as a number.

  2. 2

    Find the cause

    Check where you parse user input or API data as numbers without validation.

  3. 3

    Apply the fix

    Use int.tryParse() or double.tryParse() which return null on invalid input, and provide a default value.

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