initializeCart method
Set isPersistenceSupportEnabled
to true to turn on the cart persistence
Example:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var cart = FlutterCart();
await cart.initializeCart(isPersistenceSupportEnabled: true);
runApp(MyApp());
}
Implementation
Future<void> initializeCart(
{bool isPersistenceSupportEnabled = false}) async {
_cartItemsList = <CartModel>[];
_sharedPreference = await SharedPreferences.getInstance();
await _enableAndDisableCartPersistenceSupport(
isPersistenceSupportEnabled: isPersistenceSupportEnabled);
if (isPersistenceSupportEnabled) {
_cartItemsList = _getPersistenceCartItems() ?? [];
}
}