I am trying to get payment from my application. Everything is working fine on iOS. But on Android, my function stuck on this line:
Stripe.publishableKey = pk_key;
await Stripe.instance.applySettings(); // after this line nothings happens.
thanks in advance.
Here is my full code:
try{
Stripe.publishableKey = pk_key;
await Stripe.instance.applySettings();
var total = cartInfo.getTotal();
var customerEmail = cartInfo.address!.email;
var data = {
'email': customerEmail,
'amount': (total*100),
};
var payment_intent = await postRequest(url, data);
// widget.onLoading!(false);
print(payment_intent);
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: payment_intent['paymentIntent'],
merchantDisplayName: 'test',
customerId: payment_intent['customer'],
customerEphemeralKeySecret: payment_intent['ephemeralKey'],
merchantCountryCode: 'UAE',
)
);
setState((){});
await Stripe.instance.presentPaymentSheet();
return true;
} catch(e) {
return false;
}
EDIT:
I updated FlutterActivity to FlutterFragmentActivity in main kotlin file. But now undefined method: cotext error raised. I dont understant why? here is the full kotlin code.
https://pastecode.io/s/z86216b1
Related
I'm really new in Flutter programming. I've problem while try to get value from Future. After I get it, I want to deserialize it for further processing.
The return value from the Future is on JSON Array.
What should I do to solve this situation?
class _MyAppState extends State<BodyWidget>
{
bool loading = true;
List<Widget> listArray = [];
Dio dio = new Dio();
dynamic isicontent = null;
Future<dynamic> getOrderHistory() async {
final String pathUrl = "http://p.q.r.s/mobile/QIXGetShipmentHistory/" + await FlutterSession().get("MobileUsername");
var responseDio = await dio.get(pathUrl, options: Options( headers: {'Content-Type': 'application/json; charset=UTF-8' } ) );
print(responseDio.data); // It's works fine here...
return responseDio.data;
}
void renderIconShipmentOrderHistory()
{
var resultRespon = getOrderHistory();
print(resultRespon); //the problem is here...
}
}
The return statement needs to return a Future; something alike:
return dio.get(
pathUrl,
options: Options(
headers: {
'Content-Type': 'application/json; charset=UTF-8'
}
)
)
The async keyword from the signature likely can be removed, as there is no more await.
Obviously, not returning a Future but awaiting the result may be the other option.
I have a problem with a login that I am doing, in my emulator it works correctly but when I generate the apk and test it on the phone, the API does not work.
I already assigned the Internet permission in the .xml and made tests to use Internet images and everything fine, so I discarded the permissions.
I do not know if it gives me an error because I use an http and not an https, or if someone has an idea of what is happening here they tell me, I attach my code
Code:
void _login(BuildContext context) async {
if (!_loading) {
setState(() {
_loading = true;
});
}
//print(_username.value.text);
//print(_password.value.text);
var url = Uri.parse(
"http://taquillamedicina.mdgsystem.com/index.php?route=api/loginapp");
String var1 = 'vipmedico';
String var2 =
'xxxxx';
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
Map data = {
'username': var1,
'password': var2,
'usernameapp': _username.value.text,
'passwordapp': _password.value.text
};
var jsonResponse = null;
var response = await http.post(url, body: data);
//print(response);
if (response.statusCode == 200) {
jsonResponse = json.decode(response.body);
// print(jsonResponse);
if (jsonResponse != null) {
setState(() {
_loading = false;
});
sharedPreferences.setString("client_id", jsonResponse['client_id']);
if (jsonResponse['error'] == '1') {
Navigator.of(context).pushReplacementNamed("/list");
}
}
} else {
setState(() {
_loading = false;
});
print(response.body);
}
}
To get over this, you will have add android:usesCleartextTraffic="true" to your AndroidManifest.XML file. But as advised, this isn't solving th eproblem, it's sweeping it under the carpet, but will get your task done for now.
After I upgrade the Flutter 2.0 my app is down and I add under Anroid>Src>Main>AndroidManifest.xml
android:usesCleartextTraffic="true"
API and app is worked
I am getting this error:This expression has a type of 'void' so its value can't be used.
Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void.
code:
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.dart';
import 'package:logging/logging.dart';
import 'dart:async';
import 'package:mongo_dart/mongo_dart.dart';
main() async {
var hot = HotReloader(createServer, ['main.dart']);
await hot.startServer('127.0.0.1', 3000);
}
Future<Angel> createServer() async {
var app = Angel();
app.logger = Logger('Log')..onRecord.listen((event) => print(event));
print('start server..');
Db db = Db('mongodb://localhost:27017/wearina');
await db.open();
print('connected to ${db.databaseName}');
DbCollection userscoll = DbCollection(db, 'users');
print('${userscoll.collectionName}');
app.post('/signup', (req, res) async {
var body = await req.parseBody(); //// parseBody => Future<void> , I want => Future<Map> ):
var name = body['name'];
var lastname = body['lastname'];
var email = body['email'];
var phone = body['phone'];
var pass = body['pass'];
});
return app;
}
I don't understand what this is. I am new to flutter. This is my first app. Can someone please help me with this.
It seems that parseBody does not return a map of the pasred body. It just makes sure the body is parsed and you can access it from the req.bodyAsMap property. So your line should be:
await req.parseBody();
var body = req.bodyAsMap;
I am trying to stream a video element via my phone camera and using WebRTC. I do this as follows (snippets):
<video id="yourVideo" autoplay muted playsinline></video>
var yourVideo = document.getElementById("yourVideo");
// ...
navigator.mediaDevices.getUserMedia({audio:false, video:true}).
then(function(stream){
console.log(stream)
yourVideo.srcObject = stream
pc.addStream(stream)
})
.catch(function(error){
console.log(error)
})
This works fine in the browser and my video/camera is displayed. However, on the phone it returns me the error DOMException. I cannot find any information that can explain this.
Running it Ionic V1.X
ionic cordova run android
When I run navigator.mediaDevices this is what I see:
Is it perhaps permission related? If so, how can I fix this?
You will have to first get the device source and then try for the stream, try this way
var videoElement = document.getElementById("yourVideo");
var videoSrc = undefined;
navigator.mediaDevices.enumerateDevices()
.then(getDevices).then(getStream).catch(handleError);
function getDevices(deviceInfos) {
for (var i = 0; i !== deviceInfos.length; ++i) {
var deviceInfo = deviceInfos[i];
if (deviceInfo.kind === 'videoinput') {
videoSrc = deviceInfo.deviceId;
break;
}
}
}
function getStream() {
navigator.mediaDevices.getUserMedia({
video: {
deviceId: {
exact: videoSrc
}
}
}).
then(gotStream).catch(handleError);
}
function gotStream(stream) {
videoElement.srcObject = stream;
}
function handleError(error) {
console.log('Error: ', error);
}
I am currently working on getting all the Data object from a certain user. I thought I am already getting it, but then I noticed that it only return a DATA the second time I click the button ( means async is not working ) If you can advice, that would be a great help! Thanks!
async getData(UID) {
let container = [];
var firebaseRef = this.afd.database.ref();
let qwee = await firebaseRef.child('AllData/')
.orderByChild("UserID")
.equalTo(UID)
.on("child_added", function(snapshot) {
container.push(snapshot.val());
});
return container;
}
This is the calling function
async LoadUserData(){
this.Data = await this.provider.getData("Tom");
}
You seem to be mixing callbacks and promises.
You will need to wrap the callback in a promise and then await it.
async getData(UID) {
let container = [];
var firebaseRef = this.afd.database.ref();
let qwee = await new Promise(function(resolve,reject){
return firebaseRef.child('AllData/')
.orderByChild("UserID")
.equalTo(UID)
.on("child_added", function(snapshot) {
resolve(snapshot.val());
//container.push(snapshot.val());
});
});
container.push(qwee);
return container;
}