The named parameter 'options' isn't defined - flutter

I am creating an app to send data to database where I am using this piece of code and "The named parameter 'options' isn't defined" this problem is appearing.
final FirebaseApp app = FirebaseApp(
options: FirebaseOptions(
googleAppID: '',
apiKey: '',
databaseURL: '',
)
);

Use the documentation: https://pub.dev/documentation/firebase_core/latest/firebase_core/FirebaseApp-class.html
FireBaseApp has a static method named .configure that accepts a String name and FireBaseOptions options that returns an existing unmodified Future<FireBaseApp> or a new configured Future<FireBaseApp> asynchronously.

Related

flutter web not working due to await statement

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!

Dart - Adding more than one parameter Type: Map<String, dynamic>

I am trying to integrate Tap payments on my Flutter mobile application.
As per Tap's documentation, I need to pass src_card for VISA/MasterCard and src_kw.knet for KNET payment gateway. The code below is only accepting one parameter.
Map<String, dynamic> getOrderParams() {
var cartModel = Provider.of<CartModel>(context, listen: false);
return {
'amount': cartModel.getTotal(),
'currency': kAdvanceConfig.defaultCurrency?.currencyDisplay,
'threeDSecure': true,
'save_card': false,
'receipt': {'email': false, 'sms': true},
'customer': {
'first_name': cartModel.address?.firstName ?? '',
'last_name': cartModel.address?.lastName ?? '',
'email': cartModel.address?.email ?? '',
},
'source': {'id':'src_card'}, <--- HERE
'post': {'url': kRedirectUrl},
'redirect': {'url': kRedirectUrl}
};
}
How can I pass both src_card and src_kw.knet here? I get this error when I add another param:
The literal can't be either a map or a set because it contains at
least one literal map entry or a spread operator spreading a 'Map',
and at least one element which is neither of these.
Try src_all in place of card
'source': {'id':'src_all'},

Import variables from another .dart file to .dart file in flutter

My globals.dart file in same directory:
var apiKey= "AAAAXeuC-XXXXXXXXXXXXXXXXXXXXXXXXXX0rKLb2CWty0MHUzaZ";
var appId= "1:40338f8d8e";
var messagingSenderId= "40338";
var projectId="XXXXXXXXXXXXX";
var databaseURL= "XXXXXXXXXXXX";
I want to import these variables to main.dart file in android studio.
How I did??
import 'globals.dart' as globals;
Imported correctly, no errors
How I used??
apiKey: globals.apiKey
Its inside,
if(Firebase.apps.isNotEmpty){
await Firebase.initializeApp(
name: "HCchatbot",
options: const FirebaseOptions(
apiKey: ,
appId: ,
messagingSenderId:,
projectId: ,
databaseURL:"
),
);
}
The error:
lib/main.dart:12:27: Error: Not a constant expression.
apiKey: globals.apiKey,
^^^^^^
lib/main.dart:11:22: Error: Constant evaluation error:
options: const FirebaseOptions(
^
lib/main.dart:12:27: Context: The invocation of 'apiKey' is not allowed in a constant expression.
apiKey: globals.apiKey,
^
Can somebody help me out?? Thanks in advance
all of your values in globals.dart should be turned to const values =>
const String apiKey= "AAAAXeuC-XXXXXXXXXXXXXXXXXXXXXXXXXX0rKLb2CWty0MHUzaZ";
const String appId= "1:40338f8d8e";
const String messagingSenderId= "40338";
const String projectId="XXXXXXXXXXXXX";
const String databaseURL= "XXXXXXXXXXXX";
try again and it should work.
another solution is removing the const in the FirebaseOptions
options: FirebaseOptions

Firebase RTDB Flutter app: Multiple Databases

So, I am using the Blaze plan in Firebase and I have multiple realtime databases. I was wondering how I can connect to a specific one through my Flutter app.
FirebaseDatabase.instance.reference(); connects me to the default database, but how can I connect to another one?
Using FirebaseDatabase.instance is just a shorthand notation to getting the default FirebaseApp instance, which is typically auto-initialized from the values in your google-services.json/google-services.info.plist
You can explicitly initialize a FirebaseApp with configuration data in your code. A snippet of the relevant code from an app I happen to be working on:
final FirebaseApp app = await FirebaseApp.configure(
name: "defaultAppName",
options: Platform.isIOS
? const FirebaseOptions(
googleAppID: '....',
gcmSenderID: '...',
databaseURL: '...',
)
: const FirebaseOptions(
googleAppID: '...',
apiKey: '...',
databaseURL: '...',
),
);*/
FirebaseDatabase(app: app).setPersistenceEnabled(true);
FirebaseDatabase(app: app).reference().child("/rounds/r1").orderByValue().onChildAdded.forEach((event) => {
print(event.snapshot.value)
});

Where can i find google app id, api key, project id and gcm sender id in cloud firestore

I had this sample code, but I am not sure where can I find all the fields in my Firebase console.
final FirebaseApp app = await FirebaseApp.configure(
name: 'test',
options: const FirebaseOptions(
googleAppID: '1:1234567:ios:987654',
gcmSenderID: '987654321',
apiKey: 'ABC123456789DEF',
projectID: 'projectId',
),
);
You can find it in GoogleServicesInfo.plist file.
You should be able to see like:
<key>GOOGLE_APP_ID</key>
<string>1:111111:ios:222222</string>
<key>GCM_SENDER_ID</key>
<string>1234567890</string>
<key>API_KEY</key>
<string>ThisIsMyApiKey111</string>
<key>PROJECT_ID</key>
<string>yourId</string>