Definition conflicts with previous value - StorageGetDownloadURLTask.swift - swift

I am getting an error in Xcode when trying to build an app.
In Firebase Storage-StorageGetDownloadURLTask.swift.
Firebase Storage: 11.0.7
Flutter: 3.0.5
Xcode 12
In a few lines it presents the information:
"Definition conflicts with previous value.
Value of type 'Any?' has no member 'count'.
Value of type 'Any?' has no member 'components'"
I would like to understand why I am getting this error and how to fix it.
I already updated Firebase Storage version from 11.0.1 to 11.0.7.
I removed the podfile.lock.
I removed the Pods.
Flutter clean command, then flutter pub get.
Pod install, pod deintegrate, pod update.
And I wasn't successful.
I'm trying to update the version of my app from flutter 2.2.3 to flutter 3.0.5, I managed to run it on Android, but in Xcode it's showing this error.

The line downloadTokens = dictionary["downloadTokens"] is declaring a constant named downloadTokens with a type of Any?.
The line guard let downloadTokens = downloadTokens as? String is trying to declare a constant named downloadTokens with a type of String.
So you are trying to create two separate constants with the same name but different types, hence the error message of "Definition conflicts with previous value".
Change your code to:
guard let downloadTokens = dictionary["downloadTokens"] as? String,
downloadTokens.count > 0 else {
This combines your two lines into one creating a single constant named downloadTokens with a type of String.
This fix will resolve the other two errors since downloadTokens is not correctly of type String instead of Any?.

Related

Flutter String Interpolation remain dolloar sign after compiled

I'm using code like below
get('/api/products/detail/$name/')
it seems working fine for most of cases as I expected like below
// If variable value is 'apple'
get('/api/products/detail/apple/')
but sometimes error are catched by sentry and sentry says
My request's url was '/api/products/detail/$apple/'
This happens not all the time and it makes me so unstable
Is there anybody why this is happening and how to prevent this?
I'm using flutter 2.8.1 and dart version 2.15.1
Try below code: refer string-interpolation
var fruitName = "apple";
var apiURL = "/api/products/detail/$fruitName/";
print(apiURL);
your URL- /api/products/detail/apple/

Why am I getting "Null check operator used on a null value" from using rootBundle.load during a Flutter test?

I searched for quite a while and didn't find a clear solution to this issue on SO or other sites.
I have a Flutter test:
test('Create Repo and Read JSON', () {
Repository repository = CreateRepository();
...
}
CreateRepository() eventually calls a method with the following code:
var jsonString = await rootBundle.loadString(vendorDataFilePath);
This results in the error: Null check operator used on a null value
None of my executed code was using a null check operator (!) so where is this error coming from and how do I fix it?
After running the test in Debug mode, I found the error is actually in asset_bundle.dart within Flutter itself, not from my code.
final ByteData? asset =
await ServicesBinding.instance!.defaultBinaryMessenger.send('flutter/assets', encoded.buffer.asByteData());
It's the instance! that causes the error because instance is actually null at this point, so the null check operator (!) fails.
Unfortunately, rather than a nice descriptive error message like we normally get from Flutter, this results in a more cryptic error description directly from Dart. The root cause in my case was that an extra call is required in the test to make sure instance gets initialized.
test('Create Repo and Read JSON', () {
// Add the following line to the top of the test
TestWidgetsFlutterBinding.ensureInitialized(); // <--
Repository repository = CreateRepository();
...
}

Error: Expected a value of type 'Map<dynamic, dynamic>', but got one of type 'List<dynamic>'

I'm using hue_dart package and try to show me implemented lights in my hue bridge, but I get this Error:
Instance of `_Future<List<Light>>`
Error: Expected a value of type `Map<dynamic, dynamic>', but got one of type 'List<dynamic>'
How to convert this list to map, or how to display the list of lights?
This is my code:
class HueBridge {
searchBridge() async {
final client = Client();
final discovery = BridgeDiscovery(client);
List<DiscoveryResult> discoverResults = await discovery.automatic();
final discoveryResult = discoverResults.first;
final bridge = Bridge(client, discoveryResult.ipAddress);
print(discoveryResult.ipAddress);
final lights = bridge.lights();
print(lights);
}
}
For those who want to use the hue_dart package and encountered the same issue. A pull request have been written to fix this problem, it was accepted and merged but not released on the pub.dev.
Issue : https://github.com/Jairzinno/hue_dart/issues/8
PR : https://github.com/Jairzinno/hue_dart/pull/9
You have to know the hue_dart package is not developed by Philips, and seems to not be maintained. Indeed Philips released a V2 of their API but the package use the deprecated API V1.
To fix your issue you have 2 options :
Make the same changes as the PR (not recommended because in case of "flutter pub get" you will lose your updates).
Clone directly the GitHub of the package.
I'm actually using this package, but I'm thinking about creating a new hue_dart package to use the new V2 API.

"let json = JSON(command.arguments)" failing when built using Swift 4

The following line in cordova plugin code written for Swift 3,
let json = JSON(command.arguments)
is throwing error when built using swift 4.
Pls let me know what change needs to made to make it work in Swift 4.
command.arguments is of type [Any]! and it contains a String which is a json. I am unable to use String.data as it says [Any]! does not have member data
Error is
error: argument labels '(_:)' do not match any available overloads

Value of type 'MSTable?' has no member 'pullWithQuery'

I tried to change client page size in Azure server
it's default is 50 and I want to make it bigger
so i use Microsoft tutorial in this link
https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-ios-how-to-use-client-library#querying
var client : MSClient?
let client = MSClient(applicationURLString: "AppUrl")
let table = client.tableWithName("TodoItem")
let query = table.query()
let pullSettings = MSPullSettings(pageSize: 3000)
but when I write
table.pullWithQuery(query, queryId:nil, settings: pullSettings) { (error) in
if let err = error {
print("ERROR ", err)
}
}
there are error "Value of type 'MSTable?' has no member 'pullWithQuery'"
what is the problem ?
is the function name changed ?
Two problems:
The documentation has not been updated for current versions of Swift
(an update request has been filed). The correct function name in modern Swift is pull rather than pullWithQuery.
The pullWithQuery function is on MSSyncTable, not MSTable. Pull is part of the offline sync system. The MSTable analog is read.
More details:
The SDK itself defines the function as MSSyncTable.pullWithQuery, but one of the features of Swift 3.0 is that it renames Objective C methods when it projects them into Swift to remove redundant arguments from the name, so verbWithX(X) becomes just verb(with:x) and pullWithQuery (MSQuery) becomes pull(with:MSQuery).
For more information on Swift 3 changes please see https://swift.org/blog/swift-3-0-released/ . I believe this particular change is SE-0005: Better Translation of Objective-C APIs Into Swift
If you download the Swift quickstart from your Azure Portal then you’ll get the correct modern pattern there:
self.table!.pull(with: self.table?.query(), queryId: "AllRecords")
or with your arguments:
self.table!.pull(with: self.table?.query(), queryId: nil, settings: pullSettings)