After install flutter_bloc 8.1.0 package i just shows this error when i start adding this code ->
@override
Widget build(BuildContext context) {
return BlocProvider<CounterBloc>(
create: (context) => CounterBloc(),
child: MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Container(),
),
);
}
}
i can't find the problem i thought a the beginning it's from build ios app but i started new project and start every thing form beginning and still get the same error.
Launching lib/main.dart on macOS in debug mode...
lib/main.dart:1
: Error: A class declaration must have a body, even if it is empty.
../…/src/cubit.dart:21
Try adding an empty body.
abstract class Cubit<State> extends Bloc Base<State> {
^^^^
: Error: A function declaration needs an explicit list of parameters.
../…/src/cubit.dart:21
Try adding a parameter list to the function declaration.
abstract class Cubit<State> extends Bloc Base<State> {
^^^^
: Error: Expected ',' before this.
../…/src/cubit.dart:23
Cubit(State initialState) : super(initialState);
^^^^^^^^^^^^
: Error: Undefined name 'initialState'.
../…/src/cubit.dart:23
Cubit(State initialState) : super(initialState);
^^^^^^^^^^^^
: Error: The class 'Cubit' is abstract and can't be instantiated.
../…/src/cubit.dart:23
Cubit(State initialState) : super(initialState);
^^^^^
: Error: Expected ';' after this.
../…/src/cubit.dart:23
Cubit(State initialState) : super(initialState);
^
: Error: Expected an identifier, but got ':'.
../…/src/cubit.dart:23
Try inserting an identifier before ':'.
Cubit(State initialState) : super(initialState);
^
: Error: Unexpected token ';'.
../…/src/cubit.dart:23
Cubit(State initialState) : super(initialState);
Bloc
import 'package:equatable/equatable.dart';
class CounterBloc extends Bloc<CounterEvent, CounterState> {
CounterBloc() : super(CounterInitial(counterValue: 0)) {on<CounterEvent>((state, emit) {});}
}
abstract class CounterEvent extends Equatable {}
abstract class CounterState extends Equatable {
const CounterState();
@override
List<Object> get props => [];}
class CounterInitial extends CounterState {
int counterValue;
CounterInitial({required this.counterValue});
@override
List<Object> get props => [counterValue];
}
thanks for help.