Copy flutter pub add flutter_conscent_plugin
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get
):
Copy dependencies :
flutter_conscent_plugin : ^0.4.2
Copy import 'package:flutter_conscent_plugin/flutter_conscent_plugin.dart' ;
Initialize SDK In your application pass these fields in your app.
client_id - Pass your clientId received from Conscent.ai.
ENVIRONMENTMODE - configuration testing of different environments available.
Copy ENVIRONMENTMODE can be set as :
ENVIRONMENTMODE . SANDBOX
ENVIRONMENTMODE . PRODUCTION
The below code can be used as a sample:
Copy ConscentInitializer ( "your_client_id" , ENVIRONMENTMODE . SANDBOX );
Copy ConscentInitializer . setContentId ( 'your_content_id' );
Copy bool showContent = false ;
FutureBuilder < bool >(
future : ConscentMethods (). getContentAccess (),
builder : (context, snapshot){
if (snapshot.hasData) {
var responseData = snapshot.data;
if (responseData != null ) {
showContent = responseData;
}
return Center (
child : Stack (
children : < Widget > [
SingleChildScrollView (
controller : scrollController,
child : Container (
width : MediaQuery . of (context).size.width,
height : MediaQuery . of (context).size.height,
padding : const EdgeInsets . all ( 20.0 ),
alignment : Alignment .topCenter,
child : YourContentPage (),
),
),
if ( ! showContent)
Container (
width : MediaQuery . of (context).size.width,
height : MediaQuery . of (context).size.height,
alignment : Alignment .bottomCenter,
child : Paywall ((response) {
if (responseData != null ) {
showContent = responseData;
}
setState (() {});
})),
],
),
);
} else if (snapshot.hasError) {
return ShowYourErrorPage ();
}
},
),
These methods need to be called on the Content Page.
Copy scrollController. addListener (() {
onScollDepth = max (scrollController.offset, onScollDepth);
height = scrollController.position.maxScrollExtent;
ConscentMethods (). setScollDepthHeight (onScollDepth, height);
ConscentMethods (). onTouchListener ();
});
Copy @override
void dispose () {
super. dispose ();
ConscentMethods (). pageExitEvent ();
}
The below method is called to Logout from Conscent.ai
Copy ConscentMethods (). userLogOut ()