I am writing integration tests for Flutter App. The app let's users to take video. When writing test, how can I allow camera permission for my app inside the script for integration testing when the permission dialog appears?
With new integration_test package, you can grant permission in android inside test_driver/integration_test.dart:
// this permission grant workaround works only for android for now
Future<void> main() async {
final Map<String, String> envVars = Platform.environment;
final String adbPath =
envVars['ANDROID_SDK_ROOT']! + '/platform-tools/adb.exe';
await Process.run(adbPath, [
'shell',
'pm',
'grant',
'com.app.name',
'android.permission.CAMERA'
]);
await Process.run(adbPath, [
'shell',
'pm',
'grant',
'com.app.name',
'android.permission.RECORD_AUDIO'
]);
await integrationDriver();
}
Related
That's my code. I want to use Process.run to open a command to do something, like git clone or flutter build.
import 'dart:io';
void main() async {
print('build start');
// var res = await Process.run('git clone xxxx', []);
var res = await Process.run('flutter build windows --dart-define=RunEnv=dist', []);
print(res);
print('build end');
}
But it failed.
Unhandled exception:
ProcessException: 系统找不到指定的文件。
Command: flutter
Dart Process can't read global command variable like flutter or git? In nodejs is easy to do that. What should I do?
Your syntaxis is not right. All parameters have to supplied as a list of string, rewrite it to:
final ProcessResult res = await Process.run(
'flutter',
<String>[
'build',
'windows',
'--dart-define=RunEnv=dist'
],
);
[Edit] Link to documentation: https://api.flutter.dev/flutter/dart-io/Process/run.html [/edit]
the code below allows you to login with apple-id but I can't see the credentials, why?
Flutter Code:
final credentialUser = await SignInWithApple
.getAppleIDCredential(
scopes: AppleIDAuthorizationScopes.values);
print(credentialUser);
try this
final credential = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
);
I am having issues with Flutter web when I use await statement,
void main() async {
//debugPaintSizeEnabled = true;
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
this will not display anything on the browser and throws and error:
ChromeProxyService: Failed to evaluate expression 'title': InternalError: Expression evaluation in async frames is not supported. No frame with index 39..
I am stuck :(
debugging testing nothing worked
Run flutter channel stable followed by flutter upgrade --force
When using Firebase, you need to initalize it with options for the specific platform that you are using. Here goes and example on how to configure it for Flutter Web:
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
void main() async {
//debugPaintSizeEnabled = true;
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options = FirebaseOptions(
apiKey: 'YOUR API KEY',
appId: 'YOUR APP ID',
messagingSenderId: 'YOUR MESSAGING SENDER ID',
projectId: 'YOUR PROJECT NAME',
authDomain: 'YOUR AUTH DOMAIN (IF YOU HAVE)',
databaseURL: 'YOUR DATABASE URL (IF YOU USE FIREBASEDATABASE)',
storageBucket: 'YOUR STORAGE BUCKET',
)
);
runApp(MyApp());
}
All this information is available on your Firebase Project Console, just search for it. Hope it helps!
I want to connect the app to Metamask to get the user account and signature from the user to confirm the transaction. But the problem is that when I enter Metamask from the app, I am not asked any questions to confirm the connection and nothing happens inside Metamask, it is like only the Metamask app is opened and when I back up and return to the app, the null account is returned.
_walletConnect() async {
final connector = WalletConnect(
bridge: 'https://bridge.walletconnect.org',
clientMeta: const PeerMeta(
name: 'WalletConnect',
description: 'WalletConnect Developer App',
url: 'https://walletconnect.org',
icons: [
'https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
],
),
);
// Subscribe to events
connector.on('connect', (session) => print(session));
connector.on('session_update', (payload) => print(payload));
connector.on('disconnect', (session) => print(session));
// Create a new session
if (!connector.connected) {
session = await connector.createSession(
chainId: 97,
onDisplayUri: (uri) async => {print(uri), await launch(uri)});
}
setState(() {
account = session.accounts[0];
print(account);
});
if (account != null) {
final client = Web3Client(rpc, Client());
EthereumWalletConnectProvider provider =
EthereumWalletConnectProvider(connector);
credentials = WalletConnectEthereumCredentials(provider: provider);
yourContract = ethUtils.getDeployedContract(myAddress, client);
}
It sometimes happened to me as well.
I had just closed the MetaMask app and clicked on the button (Which triggered this function) and it worked fine.
I made a library for this, web3_connect, uses the same code and it gets the address back just fine for me
I'm making use of the flutter_facebook_auth 3.5.0 plugin to enable users to log into my app using their Facebook account.
Everything is working as expected. But when I log out and try to login again, it isn't prompting me to enter the credentials and directly logs me in.
I want it to prompt the user to enter their Facebook account credentials and then log into the app only if the authentication was successful.
Below is the SignIn code:
Future<void> signInWithFacebook(BuildContext context) async {
User? firebaseUser;
LoginResult response = await FacebookAuth.instance.login();
AuthCredential facebookCredential = FacebookAuthProvider.credential(response.accessToken!.token);
final UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(facebookCredential);
firebaseUser = userCredential.user;
switch (response.status) {
case LoginStatus.success:
final userData = await FacebookAuth.instance.getUserData();
facebookUserData = userData;
firestoreInstance.collection("users").doc(firebaseUser!.uid).set({
"userID": firebaseUser.uid,
"name": facebookUserData["name"],
"photo": facebookUserData["picture"]["data"]["url"],
"emailAddress": facebookUserData["email"],
"signUpMethod": "facebook",
"accountCreatedOn": Timestamp.now(),
"receiveOffers": true,
"isAdmin": false,
"isAuth": false,
"isSubscribed": false,
});
Navigator.of(context).pushReplacement(ScaledAnimationPageRoute(HomePage()));
break;
case LoginStatus.cancelled:
print("Facebook: User cancelled login");
break;
case LoginStatus.failed:
print("Facebook: Login error!");
break;
case LoginStatus.operationInProgress:
// TODO: Handle this case.
break;
}
}
Below is the method for logout:
await FacebookAuth.instance.logOut();
facebookUserData = {};
await authInstance.signOut().then((value) => Navigator.of(context).pushReplacement(ScaledAnimationPageRoute(SignIn())));
I think the AuthCredential needs to be cleared when the user is logging out. I'm not sure how to do it.
I'm new to Flutter. How can I fix this?
There is already an issue on the github project of the flutter_facebook_auth 3.5.0 here.
It looks like an lmitation of Facebook and not the plugin itself.
Use package named flutter_facebook_login instead...I am using this package and it is working well