Skip to content

Extracted Widget Lacks Access to error Variable, Causing Undefined Name Error #59787

Open
@stephane-archer

Description

@stephane-archer
      error: (error, stackTrace) => Center(
        child: Text(
          'Error: $error',
          style: const TextStyle(color: CupertinoColors.systemRed),
        ),
      ),

extract the widget on the Center widget

class A extends StatelessWidget {
  const A({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        'Error: $error',
        style: const TextStyle(color: CupertinoColors.systemRed),
      ),
    );
  }
}

Undefined name 'error'. Try correcting the name to one that is defined, or defining the name.

expected code:

class FavoriteFoldersErrorWidget extends StatelessWidget {
  final Object error;
  const FavoriteFoldersErrorWidget({
    required this.error,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        'Error: $error',
        style: const TextStyle(color: CupertinoColors.systemRed),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-refactoringIssues with analysis server refactoringstype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions