felangel / bloc

A predictable state management library that helps implement the BLoC design pattern

Home Page:https://bloclibrary.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix: Wrapping a const widget with a bloc builder

duck-dev-go opened this issue · comments

Description
The bloc vscode extension seems to have a problem. Wrapping a const widget with a bloc builder will move the const to the bloc builder

Steps To Reproduce
Take the following widget

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

  @override
  Widget build(BuildContext context) {
    return const Text('1000');
  }
}

And wrap it with a bloc builder and you get

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

  @override
  Widget build(BuildContext context) {
    return const BlocBuilder<BalanceCubit, BalanceState>(
      builder: (context, state) {
        return Text('1000');
      },
    );
  }
}

Which give the following error

Invalid constant value.dart(invalid_constant)

Expected Behavior
I expedited the following

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

  @override
  Widget build(BuildContext context) {
    return  BlocBuilder<BalanceCubit, BalanceState>(
      builder: (context, state) {
        return const Text('1000');
      },
    );
  }
}