Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error adding BlocProvider to app #3

Closed
Oga-Emma opened this issue May 5, 2019 · 8 comments
Closed

Error adding BlocProvider to app #3

Oga-Emma opened this issue May 5, 2019 · 8 comments

Comments

@Oga-Emma
Copy link

Oga-Emma commented May 5, 2019

Compiler message:
lib/widgets/screens/dashboard/corporate_action/cooperate_action.dart:44:16: Error: Inferred type argument 'Type' doesn't conform to the bound 'Bloc' of the type variable 'T' on 'BlocProvider'.

  • 'Type' is from 'dart:core'.
  • 'Bloc' is from 'package:generic_bloc_provider/src/bloc.dart' ('file:///Users/seven/development/flutter/.pub-cache/hosted/pub.dartlang.org/generic_bloc_provider-1.0.9/lib/src/bloc.dart').
    Try specifying type arguments explicitly so that they conform to the bounds.
    child: BlocProvider(
    ^
    file:///Users/seven/development/flutter/.pub-cache/hosted/pub.dartlang.org/generic_bloc_provider-1.0.9/lib/src/bloc_provider.dart:6:20: Context: This is the type variable whose bound isn't conformed to.
    class BlocProvider extends StatefulWidget {
    ^
@robertohuertasm
Copy link
Owner

It seems that probably the BLoC that you're using doesn't extend the Bloc abstract class.

@Oga-Emma
Copy link
Author

Oga-Emma commented May 5, 2019

import 'package:africaprudential/services/corporate_actions.dart';
import 'package:generic_bloc_provider/generic_bloc_provider.dart';
import 'package:rxdart/rxdart.dart';

class CorporateActionBloc extends Bloc{

CorporateActionBloc(){
fetchCorporateData();
}

var corporateActionsController = BehaviorSubject();
Sink get corporateActionsSink => corporateActionsController.sink;
Observable corporateStream(){
//fetch data and populate
fetchCorporateData();
return corporateActionsController.stream;
}

void fetchCorporateData(){
CorporateActions.fetch()
.then((dynamic data){
print("CORPERATE ACTIONS ==> $data");

}).catchError((){

});

}

@OverRide
void dispose() {
corporateActionsSink.close();
}

}

@Oga-Emma
Copy link
Author

Oga-Emma commented May 5, 2019

I did, there is my code. help me look into it please.

@robertohuertasm
Copy link
Owner

which version of flutter are you using?

@Oga-Emma
Copy link
Author

Oga-Emma commented May 5, 2019

Flutter (Channel stable, v1.2.1)

@robertohuertasm
Copy link
Owner

If is it not much to ask, can you share the actual code having the error?

@Oga-Emma
Copy link
Author

Oga-Emma commented May 5, 2019

import 'dart:async';

import 'package:africaprudential/bloc/corporate_actions_bloc.dart';
import 'package:africaprudential/constants/mk_routes.dart';
import 'package:africaprudential/constants/mk_strings.dart';
import 'package:africaprudential/environments/environment.dart';
import 'package:africaprudential/main.dart';
import 'package:africaprudential/rebloc/actions/common.dart';
import 'package:africaprudential/rebloc/main.dart';
import 'package:africaprudential/rebloc/states/main.dart';
import 'package:africaprudential/utils/mk_navigate.dart';
import 'package:africaprudential/utils/mk_screen_util.dart';
import 'package:africaprudential/utils/mk_settings.dart';
import 'package:africaprudential/utils/mk_theme.dart';
import 'package:africaprudential/widgets/screens/dashboard/settings_new/settings_tab.dart';
import 'package:africaprudential/widgets/screens/launch/launch_screen_page.dart';
import 'package:africaprudential/widgets/screens/login/login_page.dart';
import 'package:africaprudential/widgets/screens/splash/splash_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:generic_bloc_provider/generic_bloc_provider.dart';
import 'package:rebloc/rebloc.dart';

class BootstrapModel {
const BootstrapModel({
@required this.isFirstTime,
});

final bool isFirstTime;
}

class App extends StatefulWidget {
App({
@required Environment env,
@required this.isFirstTime,
}) {
MkSettings.environment = env;
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
}

final bool isFirstTime;

static Future bootstrap() async {
final isFirstTime = await MkSettings.checkIsFirstTimeLogin();
try {
await MkSettings.initVersion();
} catch (e) {
//
}

return BootstrapModel(isFirstTime: isFirstTime);

}

@OverRide
_AppState createState() => _AppState();
}

class _AppState extends State {
final Store store = reblocStore();

final MkScreenUtilConfig screenConfig = const MkScreenUtilConfig(
width: 375,
height: 812,
allowFontScaling: true,
);

@OverRide
void dispose() {
store.dispatcher(const OnDisposeAction());
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
return MkTheme(
child: BlocProvider( //HERE IS THE LINE
bloc: CorporateActionBloc,
child: StoreProvider(
store: store,
child: FirstBuildDispatcher(
// Initialize action
action: const OnInitAction(),
child: Builder(
builder: (BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: MkStrings.appName,
color: Colors.white,
theme: MkTheme.of(context).themeData(Theme.of(context)),
builder: (context, child) {
return Builder(
builder: (BuildContext context) {
MkScreenUtil.initialize(
context: context,
config: screenConfig,
);
return child;
},
);
},
onGenerateRoute: (RouteSettings settings) {
return MkNavigateRoute(
builder: (_) => LaunchScreenPage(),
settings: settings.copyWith(
name: MkRoutes.start,
isInitialRoute: true,
),
);
},
);
},
),
),
),
),
);
}
}

@robertohuertasm
Copy link
Owner

Sorry, it's been a while and I hadn't the time to look more into this. Is this still an issue? If not I will close it next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants