method not available: ext.flutter.inspector.setPubRootDirectories - flutter

I am getting the error below when I try to download a file using flutter_downloader. My Google searches seem to indicate that this is a problem with Firebase. I have firebase_messaging installed but the issue only comes up when I try to downlaod a file using flutter_downloader.
Error handling 'serviceExtension' custom request: method not available: ext.flutter.inspector.setPubRootDirectories
Please assist.
Herewith the Flutter code snippet for the downloader;
IconButton(
icon: Icon(Icons.download),
onPressed: () async {
final status = await Permission.storage.request();
if (status.isGranted) {
final externalDir = await getExternalStorageDirectory();
final id = await FlutterDownloader.enqueue(
url: files[i].file,
fileName: 'filename',
savedDir: externalDir.path,
showNotification: true,
openFileFromNotification: true,
);
} else {
print('Permission denied');
}
},
),

Related

Cant open whatsapp app from my flutter app, this can be run when debugging but when download on playstore it doesn't work

I used this code to redirect to whatsapp app, but its only works in debugging mode, when i download my app from play store deosnt work
onTap: () async {
var whatsappApp = Uri.parse("whatsapp://send?phone=$contactusWhatsapp&text=hello");
if (await canLaunchUrl(whatsappApp)) {
await launchUrl(whatsappApp);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("WhatsApp is not installed on the device"),
),
);
}
},
You can use as below
onPressed: () async {
await launch(
"https://wa.me/you write the number here",
forceSafariVC: false,
forceWebView: false,
headers: <String, String>{
'my_header_key': 'my_header_value'
},
);
},
To use it this way, you also need to install the url launcher package.

Stripe wont intialize paymentsheet

I am trying to implement Stripe to my flutter app, but i am running in to this issue:
StripeException(error: LocalizedErrorMessage(code: FailureCode.Failed, localizedMessage: No payment sheet has been initialized yet, message: No payment sheet has been initialized yet, stripeErrorCode: null, declineCode: null, type: null))
My current code is:
Future<void> makePayment() async {
final response = await http.post(
Uri.parse(
api_string,
),
headers: {"Content-Type": "application/json; charset=utf-8"},
body: json.encode({"Amount": "250"}),
);
var data = json.decode(response.body);
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: data['clientSecret'],
merchantDisplayName: 'Flutter test app',
applePay: true,
googlePay: true,
style: ThemeMode.dark,
testEnv: true,
merchantCountryCode: 'DK',
),
);
setState(() {});
await displayPaymentSheet();
}
Future<void> displayPaymentSheet() async {
try {
await Stripe.instance.presentPaymentSheet();
} catch (e) {
print(e);
}
}
I have checked the official flutter_stripe documentation, but the example with my API changed gives the same error, and my api return "clientSecret": Secret}
As stated in the comment, the fix was to add a merchantId to the Stripe initialization

How to pass data to cloud function file in flutter

I am new to flutter and I have just created app that accepts payments from user using flutter_stripe: ^2.1.0 plugin. The amount in cloud function file index.js is fixed but I want to pass the amount that is calculated dynamically. Here is my code.
Future<void> makePayment() async {
final url = Uri.parse(
'https://us-central1-carwashapp-376b6.cloudfunctions.net/stripePayment');
final response =
await http.get(url, headers: {"Content-Type": "application/json"});
paymentIntentData = json.decode(response.body);
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: paymentIntentData['paymentIntent'],
applePay: true,
googlePay: true,
style: ThemeMode.light,
merchantCountryCode: 'US',
merchantDisplayName: 'Kleen My Car',
),
);
setState(() {});
displayPaymentSheet();
}
Future<void> displayPaymentSheet() async {
try {
await Stripe.instance.presentPaymentSheet(
parameters: PresentPaymentSheetParameters(
clientSecret: paymentIntentData['paymentIntent'],
confirmPayment: true));
setState(() {
paymentIntentData = null;
});
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('Payment succeeded')));
} catch (e) {
print('error error error');
}
}
and here is my index.js file's code
const functions = require("firebase-functions");
const stripe = require("stripe")(functions.config().stripe.testkey);
exports.stripePayment = functions.https.onRequest(async (req, res) => {
const paymentIntent = await stripe.paymentIntents.create(
{
amount: 120,
currency: "USD",
},
function (err, paymentIntent) {
if (err != null) {
console.log(err);
} else {
res.json({
paymentIntent: paymentIntent.client_secret,
});
}
}
);
});
Any kind of help is much appreciated. Thank you so much!
You need to adapt this line:
final response = await http.get(url, headers: {"Content-Type": "application/json"});
(Firstly, it makes no sense to give a content type on a GET, as GETs don't have any content. Remove that header.)
You could change to a POST and add the amount as a parameter, or leave it as a GET and add the amount to the URL.
With a POST, add (for example) body: {'amount': amount.toString()}
With a GET, add it to the URL, as follows:
final uri = Uri.https('us-central1-carwashapp-376b6.cloudfunctions.net', '/stripepayment', {'amount': amount.toString()});
In your cloud function access amount from the req. (For example, in the GET example, it would be req.query.amount as string.)
We also pass up other parameters like email, unique order id (to be used as the idempotency key), etc.
in index.js file change
const paymentIntent = await stripe.paymentIntents.create(
{
amount: 120,
currency: "USD",
},
to
const paymentIntent = await stripe.paymentIntents.create(
{
amount: req.query.amount,
currency: req.query.currency,
},
and deploy your function.
after that, in makepayment function, change your URL to
https://us-central1-carwashapp-376b6.cloudfunctions.net/stripePayment?amount=$amount&currency=$currency.
In this way, you can pass different amounts every time by changing the value of $amount variable in the URL.

Choose a file (image, pdf, doc) and upload to server flutter android

I'm working with ASP.NET rest APIs. The task is I have to choose only one thing i.e image, pdf, docs file and send it to server. For picking files, I'm using the following library
file_picker: ^3.0.3
After successfully picking the file when I send it to the server, the response from the server is 403 forbidden.
// this is picking image code
ElevatedButton(
onPressed: () async {
FilePickerResult result = await FilePicker.platform.pickFiles();
if (result != null) {
PlatformFile file = result.files.first;
ApiClient.apiClient.uploadDocumentApi(file.path);
}
},
style: ElevatedButton.styleFrom(
primary: kPrimaryColor,
elevation: 0.0,
),
child: Text('Select'),
),
// this is API code
Future<void> uploadDocumentApi(String filePath) async {
print('pathh: ' + filePath);
String url = 'www.example.com';
var request = http.MultipartRequest(
'POST',
Uri.parse(url),
);
// request.files.add(await http.MultipartFile.fromPath('', filePath));
request.files.add(
http.MultipartFile(
'',
File(filePath).readAsBytes().asStream(),
File(filePath).lengthSync(),
filename: filePath.split("/").last,
),
);
http.StreamedResponse response = await request.send();
print(response.statusCode);
print(response.reasonPhrase);
if (response.statusCode == 200) {
print('success');
print(response.stream.bytesToString());
} else {
print('fail');
print(response.reasonPhrase);
}
}
As the error code indicates its related to authentication of your request. make sure your set your jwt correctly in your request header if needed and check it with backend side

flutter downloader and path provider on ios

I have managed to make flutter downloader and the path provider work on android but it won't work on ios saying that this is a android only operation , what's wrong ?
here is the code :
secondaryActions: <Widget>[
IconSlideAction(
caption: 'Download',
color: Colors.green,
icon: Icons.arrow_circle_down,
onTap: () async {
final status = await Permission.storage.request();
if (status.isGranted) {
final externalDir = await getExternalStorageDirectory();
final id = await FlutterDownloader.enqueue(
url: f.url,
savedDir: externalDir.path,
showNotification: true,
openFileFromNotification: true);
} else {
toast('Permission Denied');
}
},
),
For iOS, after having permission, you should use final externalDir = await getApplicationDocumentsDirectory() since getExternalStorageDirectory() is not supported for iOS.
You can do an OS check:
var externalDir;
if (Platform.isIOS) { // Platform is imported from 'dart:io' package
externalDir = await getApplicationDocumentsDirectory();
} else if (Platform.isAndroid) {
externalDir = await getExternalStorageDirectory();
}