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

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

Related

How to interact with native apps using appium-flutter-driver & webdriverIO project

I'm using appium-flutter-driver & webdriverIO to automate the flutter mobile app.
I have a use case in my application where clicking on
Mail us button opens Gmail app with subject, body
Call us button opens Dailer app with phone number
I want assert/verify that gmail/phone app is opened. either one of following is fine
verifying that gmail/phone app package name
verifying the subject, content in gmail compose screen is also fine
I see here https://github.com/appium-userland/appium-flutter-driver that
await driver.switchContext('NATIVE_APP');
await (await driver.$('~fab')).click();
what is ~fab means here?
How to find elements using ID, text, class in this case and perform click, enterText, etc operations?
I'm not sure what ~fab means. But the available finders are mentioned here, with links to the documentation. The available commands are mentioned here, with links to the documentation.
An example of a finder by semantics label with a click:
element = FlutterElement(self.driver, FlutterFinder().by_semantics_label('Back'))
element.click()
An example of entering text:
driver.execute_script('flutter: enterText')
Got these examples from here.

Read the contents of a .csv file in Google Drive

I have a public .csv file on my Google Drive and I want to pull the file and display it in my flutter app. I figured that I need the fileID, the OAuth token and the client ID,I already got these. I also have a fully working sign-in page. But I can't figure out what is the exact methodology of fetching the file. I know that there is some content of this exact question online, I am a beginner, those posts were old, and some functions were deprecated, I couldn't understand them.
You can use the export api to get this
"https://www.googleapis.com/drive/v3/files/[FILEID]/export?mimeType=[mimeType]&key=[YOUR_API_KEY]"
Refer https://developers.google.com/drive/api/v3/reference/files/export for more details
Please note that is restricted to 10 Mb per file
Edit
add these dependencies
dependencies:
googleapis: any
google_sign_in: any
Implement google signing
final googleSignIn = signIn.GoogleSignIn.standard(scopes: [drive.DriveApi.DriveScope]);
final signIn.GoogleSignInAccount account = await googleSignIn.signIn();
Create a firebase project and enable google signin and link it with your project. Download its Json and add it to the project too.
Goto cloud console and enable Google Drive API
After the login is complete you can use the download method to download the file
Future<File> download(String id, String filename, {Function(int, int) onDownloadProgress});
Check this tutorial for reference
https://betterprogramming.pub/the-minimum-guide-for-using-google-drive-api-with-flutter-9207e4cb05ba

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;
}

Is there a way to send SMS on flutter without user interaction?

I'm trying to send SMS from my flutter app when a button is pressed. I'd like to do this without user interaction. I know i can launch the SMS app using url_launcher.
I tried using the sms package from pub but flutter says the api is outdated.
I'd like to do this purely in dart if possible.
I'm using the package sms_maintained. refer to package for latest version.
Code sample from package.
import 'package:sms/sms.dart';
void main() {
SmsSender sender = new SmsSender();
String address = someAddress();
...
sender.sendSms(new SmsMessage(address, 'Hello flutter!'));
}
I't provides other methods as well.
Querying, filtering, contact info, receiving and deleting as well.
For sending the a sms you'd need the necessary permissions.
SEND_SMS
And for other functionalities.
RECEIVE_SMS
READ_SMS
READ_CONTACTS
An extensive list of them are located here.
flutter AndroidManifest.xml is location => android/app/src/main/AndroidManifest.xml
EDIT #:
The package is no longer maintained. you may manually link to files from this repo
pubspec.yaml
dependencies:
...
sms_maintained:
path: plugin_folder_path

Google Drive Sdk- Audio & Video Streaming in iOS Application

Hi Google Drive Staff,
I have tried to stream video files from Google Drive(Without Downloading). But I gets alerts that Sign In. I have went thoroughly with Dr. Edit sample App but i did not found any solution. I tried with downloadUrl , embedLink, webContentLink, alternateLink. All gives message to sign In. When i tried with exportsLinks i get a Null Message. What is the problem Here. If U have any suggestion Please Let me Know...
I have tried with Google Drive for iOS in iPod, there we can stream Video without Downloading.
Please suggest me to resolve this issue
Thanks in Advance...
I could solve it just by appending the access_token to the download url
audiofile.strPath=[NSString stringWithFormat#"%#&access_token=%#",downloadUrl,accessToken];
pass the strPath to your avplayer object to play music.
I did not try the video part. but i think a similar approach should work.
you can fetch the access token from the GTMOAuth2Authentication object
Note that you might need to refresh it if its expires.
Hope this helps you.
Regards
Nitesh
I think it depends what you mean by "stream". Last time I looked, the download links all had a content disposition: attachment header, which instructs the browser to download rather than render the content.
If you have your own client fetching the url, you can choose to ignore that header and do what you like with the content as it is fetched. imho, it would be nice if the client could add a parameter to the url to indicate to the Google servers that it wants the content to be rendered v. downloaded, but hey ho.
You need to authorize all requests to downloadLinks with an Authorization header. Read more about the authorization and learn how to retrieve your users an access token on https://developers.google.com/drive/about-auth