import 'dart:convert'; import 'dart:typed_data'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:medcify/models/order_item.dart'; import 'package:medcify/network/api_provider.dart'; import '../../../components/alert.dart'; import '../../../constants.dart'; import '../../../helpers.dart'; import '../../../models/banner_item.dart'; import '../../../models/medicine_item.dart'; import '../../../navigation/navigation.dart'; abstract class QrCodeState{} class QrCodeInitial extends QrCodeState{} class QrCodeLoading extends QrCodeState{} class QrCodeSuccess extends QrCodeState{} class QrCodeFailure extends QrCodeState{ String error; QrCodeFailure(this.error); } class QrCodeCubit extends Cubit { QrCodeCubit() : super(QrCodeInitial()); Uint8List? image; String name = ""; String url = ""; Future fetchQrCode() async{ emit(QrCodeLoading()); final response = await ApiProvider.instance.fetchQrCode(); if(response.status ?? false){ name = response.name ?? ""; url = response.url ?? ""; String data = response.image ?? ""; if(data.isNotEmpty){ image = const Base64Decoder().convert(data.split(',').last); } emit(QrCodeSuccess()); }else{ emit(QrCodeFailure(response.message ?? "Something went wrong")); } } }