Flutter 'get method was call on nul' Error - flutter

I was doing news app on Flutter and I was working with non-null safety because I was doing the older project.But then I started getting errors and I change my version to make the app with null-safety. Anyways, I changed the version re-edit the code I was thinking that I did great work but suddenly I'm getting this error right now. How can I fix this?

in your import do like below.
import 'package:http/http.dart' as http;
call your response like below...
http.Response response = await http.get(
endPointUrl,
);
As of my knowledge we cant declare http with var....thats why its shows error...above code will work

Related

Linking Patreon API with a Flutter application

I am very new to using Flutter and have never properly used an API without help. I want to make my application free (without tons of ads) so I was hoping to create a Patreon to support it's upkeep. When looking for tutorial videos online or any examples of code to use for either Flutter or any other languages I know how to use, I came up empty handed. So I was posting this question here hoping that someone could help me link the Patreon API to Flutter. The documentation doesn't say it connects directly to Flutter, so you'll have to use another language to access the information (best bet is Javascript or Python on my opinion) and relay that too Flutter.
I (and possibly other people) would need a button created for OAuth login through Patreon (that works on both iOS and Android). When the user goes through the login, it needs to grab which tier they are supporting, their username, and when their subscription will renew (monthly or yearly?). This then needs to be translated to Text widgets (displaying the tier and/or username) and a "visible:" property for Visibility widgets (displaying certain content based on the user's monthly subscription and making the same content invisible or put behind a newly visible lock page when their subscription ends/expires).
Sorry I know this is a lot to anwser, but I'm not very experienced with APIs and Flutter. I will appreciate any anwser that helps because I really want to make my app without tons of advertisements and I'm hoping this question will help other Flutter developers with the same goal of supporting their development financial without tons of advertising effecting the user's experiences on the app.
Patreon API OAuth Documentation
https://docs.patreon.com/#oauth
Flutter JS (I think this may help connect with the Patreon API, but I'm not sure?)
https://pub.dev/packages/flutter_js
Examples of code and a step by step guide would be fantastic, but anything will help. Thank you again!
You want something like this:
import 'package:http/http.dart' as http;
static Future<http.Response> getResponse(String endpoint)
async {
print ("API REQUEST $endpoint");
http.Response response = await http.get(
Uri.parse('$BASE_URL$endpoint'),
headers: {
name:val,
name2:val
},
);
print ("API RESPONSE ${response.body}");
if (response.statusCode != 200) {
throw "Argh! Put error info here";
}
return response;
}

Rerun axios.get in useEffect when url parameter changes

I have been learning React Hooks recently. I have researched for a few days to know how to fetch data and realized that there was axios.
I am using it to fetch data but the problem is it is not working properly when the parameter changes in the url. I have explored tonnes of posts related to this issue here but never got proper ideas.
Here is what I have tried so far. I simplified my code in the link: MyCode.
In my code, when a checkbox value changes, the axios fetches different data.
How can I rerun axios in useEffect when the url parameter changes?
How can I rerun axios in useEffect when the url parameter changes?
Using a dependency
useEffect(() => {
axios.get(`http://myURL/employee_id/${someParam}`).then((response) => {
setEmployee(response.data);
});
}, [someParam]);
Although if I were you I would make the axios call inside changeId function directly. useEffect is overused sometimes. If you can make an action imperatively, there is no need to tie it to a variable and then track it also in useEffect for taking an action.

How to make user download/save file from the flutter app?

I want user to be able to store txt/doc/pdf file generated by flutter app wherever he/she wants on his/her phone. For example, if it were a webapp, this would be achieved by sending HTTP header Content-Disposition: attachment; filename=MyFileName.txt. Is it possible at all in flutter application? I tried looking at url_launcher, flutter_downloader, flutter_webview_plugin or flutter_web_browser packages, but non of them offer relevant functionality. I would appreciate any tips regarding this issue.
Getting the directory
You can use flutter_file_dialog to get the user the choose the location with this code:
final params = SaveFileDialogParams(sourceFilePath: "path_of_file_to_save");
final filePath = await FlutterFileDialog.saveFile(params: params);
print(filePath);
Saving the file
For that just use path_provider : https://flutter.dev/docs/cookbook/persistence/reading-writing-files

Unable to instantiate the URL

I have written the first code for mobile automation, but stuck while instantiating the URL. Getting error
"URL can not be resolved to a type"
driver=new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
First, make sure you have correct import of URL class:
import java.net.URL;

Suddenly Facebook API stopped working on Windows Phone

My code hasn't changed, it was working yesterday or so.
I can oauth, get the token but then doing the following:
WebClient wc = new WebClient();
wc.DownloadStringCompleted += result;
wc.DownloadStringAsync(new Uri("https://graph.facebook.com/me&access_token=xxxTOKENxxx", UriKind.Absolute));
Returns a NotFound WebClient exception: "The remote server returned an error: NotFound."
Strange thing is that when pasting that same url on Chrome or IE it does work(PC).
Tried on Emulator and on 2 different real WP devices, even pasting the same url on the WP browser.
Feels like facebook is rejecting Windows Phone for some reason?
Anyone has an idea of what might be happening?
look like there is a bug on Facebook being tracked
click here if you want to follow
https://developers.facebook.com/bugs/367369176650486?browse=search_4fd82eadc62186861827790
after reading the link someone says graph.beta.facebook.com does work instead of graph.facebook.com
I can confirm its not you. WP7 sample from the SDK from GitHub is failing. ASP.NET sample is now returning an "Error occured in . Please try again later." error. As you noted, copying and pasting the URL into IE resolves and returned the expected JSON. Clearly something has changed.