I want to implement rate and share button in my app so I am using url_launcher and here I want to put url of my app.
Currently it is working as
url="https://play.google.com/store/apps/details?id=in.learncodeonline.lco";
but I want this type
url="https://play.google.com/store/apps/details?id={packageName}"
Just call this function with package Name
void shareAnyApp(String packageName) async {
var url = "https://play.google.com/store/apps/details?id=$packageName";
if (await canLaunch(url)) {
await launch(url);
}
}
To Get Current App Package use Package_info
PackageInfo packageInfo = await PackageInfo.fromPlatform();
shareAnyApp(packageInfo.packageName );
Related
I've been building an ios app and in it, it'll download a bunch of pdf from an API and save it to the local storage using the path_provider package in flutter:
This is the code I use to fetch the path:
Future<String> get localPath async {
final directory = await getApplicationDocumentsDirectory();
currentDir.value = directory.path;
return directory.path;}
And this is how I save it to the device:
Future<void> saveFilesToLocal(String url, String fileName) async {
try {
final path = await localPath;
final file = File('$path/$fileName');
if (await file.exists() == false) {
final response = await Dio().get(url,
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
receiveTimeout: 0));
final raf = file.openSync(mode: FileMode.write);
raf.writeFromSync(response.data);
await raf.close();
} else {
print("file already exists");
}
} catch (e) {
print('error: $e');
}
}
After I download and save the files to the storage, it'll be displayed as a gridview in the home page. To fetch that list of files I use this:
List<FileSystemEntity> files = [];
Future<void> getFilesList() async {
files.clear();
final path = await localPath;
Directory dir = Directory('$path');
files =
dir.listSync(recursive: true, followLinks: false);
update();
}
And all of this works fine in the ios device. But the current issue I'm facing while trying to run it on web is:
The package path_provider is not available for flutter web. I've been asked to create it as a web app too and I can't find an alternative for it. While looking for one I saw a post saying flutter web won't allow access to a device's local storage like that so it's not possible. Is it true? Is there a workaround? If it's about security, the app will only be run on specific devices. It won't be given to the public.
i would like to import in my flutter application, files from "Files" and "Photos" default ios/android/macos applications.
Have you got any solution to do that ?
Thank you
See this documentation: https://docs.flutter.dev/cookbook/persistence/reading-writing-files
add to pubspec (https://pub.dev/packages/path_provider):
path_provider: ^2.0.11
import package:
import 'package:path_provider/path_provider.dart';
Find local path:
Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
create reference:
Future<File> get _localFile async {
final path = await _localPath;
return File('$path/counter.txt');
}
read data:
Future<int> readCounter() async {
try {
final file = await _localFile;
// Read the file
final contents = await file.readAsString();
return int.parse(contents);
} catch (e) {
// If encountering an error, return 0
return 0;
}
}
You can use image_picker package to access user's photos with the required permissions;
iOS
Android
You can use the flutter File Picker package.
https://pub.dev/packages/file_picker
I m trying to send SMS directly from my flutter app but I m not finding good package, I try flutter SMS but its open SMS default app or I also try telephony its send SMS only to android
Try "**url_launcher**" flutter plugin, using this you can directly call and send sms from the app you built.
//you can use it using this method as reference
// this is for calling to a required number
Future _callContact(BuildContext context, String number) async {
final url = 'tel:$number';
if (await canLaunch(url)) {
await launch(url);
}
else {
const snackbar = SnackBar(content: Text('Can\'t make a call'));
Scaffold.of(context).showSnackBar(snackbar);
}
}
// this is for sms
Future _smsContact(BuildContext context, String number) async {
final url = 'sms:$number';
if (await canLaunch(url)) {
await launch(url);
} else {
const snackbar = SnackBar(content: Text('Can\'t make a call'));
Scaffold.of(context).showSnackBar(snackbar);
}
}
Flutter 2 announced just few days ago and some packages updated for web like Image Picker. I'm trying to get image and upload it to cloud storage. Image picker working very well but when
I want to upload image to storage it gives me error.
Unsupported operation: Platform._operatingSystem
UI Code
onImageSelect: (selectedImage) async {
try {
final url = await Get.find<FirebaseStorageService>()
.uploadProfilePicture(
customer.uuid, File(selectedImage.path));
print(url);
} catch (e) {
print(e);
}
customer.profileImageUrl = selectedImage.path;
_isImageSelected = true;
}),
Service Class funciton:
class FirebaseStorageService {
final FirebaseStorage _firebaseStorage = FirebaseStorage.instance;
Reference _storageReference;
Future<String> uploadProfilePicture(
String userID, File uploadingImagePath) async {
_storageReference = _firebaseStorage
.ref()
.child(userID)
.child('images')
.child("profile-photo.png");
var uploadTask = _storageReference.putFile(uploadingImagePath);
var url = await (await uploadTask).ref.getDownloadURL();
return url;
}
}
I tried flutter clean and flutter upgrade. I also searched old questions and some of them used html.File instead of dart:io library but firebase_storage:7.0.0 package only accept File class which is from dart:io library.
Code work on Android and IOS but not web.
I'm using stable channel.
I am working with google books in my flutter project.
im trying to create a method that that will call the diffrent books URL's that i have stored in a List and call the list back using a future builder.
The list look somthing like this:
List<String> toBeReadBooksList = ['https://www.googleapis.com/books/v1/volumes?q=1086782593+isbn'];
You can do it a way that similar to this:
final url = 'https://www.googleapis.com/books/v1/volumes?q=1086782593+isbn';
final response = await http.get(url)
if (response.statusCode == 200) {
// Here you need to parse data from response, you should replace it with your realization:
return Data.fromJson(jsonDecode(response.body));
} else {
throw Exception('Failed to load data from $url');
}
You can read more about how to work with requests and responses to/from the Network in Official Documentation.
Import url_launcher plugin import 'package:url_launcher/url_launcher.dart';
and in your pubspec.yaml dependecies url_launcher: ^5.7.10
add this and call it to open the selected url
_launchURL() async {
const url = toBeReadBooksList[0];//your list url
if (await canLaunch(url)) {
await launch(url);
}
else {
throw 'Could not launch $url';
}
}