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/
Related
I came across to make this type of request:
I need to map List<int>ids query parameter id like this:
/api/available-specialists?id=3176&id=3170
And is it possible to make this request even without retrofit in dart?
I found the solution.
In the place, where you create your Dio instance, update ListFormat if needed. BaseOptions(listFormat: ListFormat.multi). ListFormat.multi is default value and it helps to convert your list of params into string like this: foo=value&foo=another_value. In my case everything works without updating ListFormat.
In the repository, where you define your methods, specify your Query:
#Query('status') List<int> statusList,
Run flutter pub run build_runner build --delete-conflicting-outputs then re-run your app.
When you make the request, you can see such url in logs: https://some-api/end-point/?status=2&status=4
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();
...
}
I want to get data from firebase cloud
Data means my chatApp's messages.
but in my code i got error
android studio suggest me to add nullcheck(!) to
final messages = snapshot.data!.documents;
but it not working
Try to add the null-check and fix your typo: messgeText => messageText.
You r using Flutter 2.5.0 and now for the latest flutter version the syntax are changed for Firebase . Try this way:
final message = snapshot.data!.data()
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.
I was trying out includeObject method with my livequery in one of my project. I am using Parse_Server_Sdk for this back4App database. Also, I am using flutter parse_server_sdk latest version 1.0.26.
What i want is i have a list of events. So whenever a new event is added in my database then it should trigger the subscription method. I have used following code and it works as well. But, only thing i have issue with is i don't get the includedobject i have added in QueryBuilder.
QueryBuilder<ParseObject> parseQuery =
QueryBuilder<ParseObject>(ParseObject(tblEvents))
..whereEqualTo(tblEventUserId, currentUser);
parseQuery.includeObject([tblOrganizerId]);
Subscription subscription = await liveQuery.client.subscribe(parseQuery);
subscription.on(LiveQueryEvent.create, (value) {
print("val : ${value}");
print("val : ${value.runtimeType}");
});
Output :
val : {"className":"Group_Events","objectId":"uotQ6BpT4C","createdAt":"2020-08-27T07:18:26.581Z","updatedAt":"2020-08-27T07:18:26.581Z","organizer_id":{"__type":"Pointer","className":"Organizer","objectId":"t9M1oyZHh4"},"user_id":{"__type":"Pointer","className":"_User","objectId":"Hx5xJ5ABxG"},"weight":1}
I/flutter (30335): val : ParseObject
I have also evaluated the expression. But, there is only limited pointer data to "tblOrganizerId". I am not getting whole data of that table.
Can anyone suggest me a workaround or a solution?
Thanks.
I would use the "ParseLiveListWidget". It should be perfect for this scenario.
You can find an example here.
Additional information is in this README.
(Use version 1.0.27 for some important bug fixes.)