Flutter Open App Setting, bluetooth, wifi, location settings
Hi Guys, Welcome to Proto Coders Point, In this Flutter Tutorial Article we will learn how to open app settings in flutter.
Flutter App_Settings Package
A Flutter package by which you can easily open Android & iOS devices settings pages such as: Open App Settings, Location Settings, device, Bluetooth Settings, WiFi settings, NFC, Battery optimization settings, Display setting, sound settings by just one button click using flutter app_settings package in your flutter project.
Video Tutorial on App Settings flutter plugin
Getting Started
App_Settings flutter package Installation
In your flutter project, open pubspec.yaml file and under dependencies section you need to add app_settings flutter library
dependencies: app_settings: ^4.1.1
after adding the library hit pub get button on pubspec.yaml file top right or else run command in IDE terminal ‘flutter pub get’
Import it
Once you have successfully added the required package to open flutter app settings, now you need to import app_settings.dart file.
import 'package:app_settings/app_settings.dart';
Platform Configuration
Android
You can directly use system settings screen like: WIFI Settings, Security, Device Setting, date Setting etc, but in some cases, to access bluetooth setting page or Location settings page, you need to add access permission in your AndroidManifest.xml file
TIP: If using Objective-C for iOS in your project, you will need to add use_frameworks! to your Runner project podfile in order to use this Swift plugin:
- target 'Runner' do
use_frameworks!
Flutter App_ Setting package usage
Below are code to directly open setting page such as eg: Bluetooth Settings
Hi Guys, Welcome to Proto Coders Point. In this flutter tutorial article, will explore how to pick files in flutter app.
File Picking in native platform like android & iOS is quite easy, but is even easier in flutter by using packages like file_picker.
So this flutter article is all about picking different types of files like Image, Video, Audio, pdf, doc etc.
Flutter File_Picker package
This package is very easily to use to pick file from native file explorer, it allows you to use file explorer of native platform to pick files , if support single & multiple file picking & also extension filtering is supported in selecting files.
Feature of file_picker
Invoke native platform OS picker to pick different types of files.
Developer can list type of extension a user can pick Eg: jpg, png, pdf etc.
Single and multiple file picks possible.
file type filtering (media,image,video, all type).
Let’s Get Started with implementing file_picker in flutter app
Step 1: Create a flutter project & all file_picker dependencies
Create a new flutter project in your favourite IDE & add flutter picker package
open pubspec.yaml file & add file_picker
dependencies:
file_picker:
then hit pub get or run flutter pub get command to download the package into your flutter project.
Step 2: import file_picker.dart
once you have added the dependencies package succesfully, to use file_picker you need to import it wherever required.
import 'package:file_picker/file_picker.dart';
Now, you can easily pick files in flutter app.
Properties of PickFiles class
Properties
Description
dialogTitle:
Gives a Title to picker dialog
type:
Define type of file to pick Eg: FileType.any FileType.image FileType.video FileType.audio FileType.custom [ should define allowedExtensions ]
allowedExtensions: [….]
Allow only specific extensions file to be picker Eg: allowedExtensions: [‘jpg’, ‘pdf’, ‘png’],
allowMultiple: true/false
allow Multiple files can be picked.
Pick Single File
If you want to pick single file in flutter, use below code
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result == null) return; // if user don't pick any thing then do nothing just return.
PlatformFile file = result!.files.first;
//now do something with file selected
Multiple file picking in flutter
Then, if you want to pick more then one file at once(multiple file picking), use below code.
FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true);
if (result == null) return;
List<File> files = result!.paths.map((path) => File(path!)).toList();
// now do something with list of files selected/picked by a user
The files picked by a user is stored in List<File> array.
Pick particular type of file extensions
Sometimes, you want a user to only pick a particular type of file extensions, say jpg, png, pdf, doc etc in that case we can use 2 properties in pickFiles() class i.e
FilePickerResult? result = await FilePicker.platform.pickFiles(type: FileType.custom,allowedExtensions: ['jpg','pdf']);
if (result == null) return;
PlatformFile file1 = result1!.files.first;
Now, native file explorer will only show the file with defined extensions
Get Full Details of picked file in flutter
So, now you have picked files using filepicker & now you want to read the details of file like name of file, size of file, type of file(extensions) & path of selected file. below is the code
Important Note: To use new Material you navigation bar widget you need to switch to flutter master channel.
How to change flutter channel to master
Step 1: In your IDE Terminal run below command ” flutter channel master “
Step 2: Then flutter update/upgrade Type ” flutter upgrade“
Step 3: Restart your IDE
Thus, now you can use flutter material you navigation bar, Does it replace the aged flutter bottom navigation bar? let’s implement it and try it out now.
Let’s get started
Flutter material you Navigation bar widget
The first Material you widget i.e. “NavigationBar” is now been approved as new alternative way of adding bottom navigation bar into flutter app & its available to use in flutter master channel.
Therefore, flutter developers need to switch master channel to make use of material you in flutter.
Snippet Code
NavigationBar(
height: 65,
selectedIndex: 0,
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
animationDuration: Duration(seconds: 2),
onDestinationSelected: (index) {
// callback to change between pages
},
destinations: const [
// list of NavigationDestination Tabs
],
),
NavigationBar Properties
Properties
Description
Example
destinations:[//list]
List of Navigation Destination. note: destination tab list must be two or more.
below
selectedIndex:
Active tab of Navigation bar. index starts from 0,1….n
selectedIndex : 2
onDestinationSelected:(index)
Is a method is used to display pages of nav bar when user click on tab.
example in below complete code.
backgroundColor:
Change color of nav bar
backgroundColor: Colors.blue.shade200,
height:
specify height of nav bar
height: 60
labelBehavior:
We can hide or show or show only selected tab label
How to change Naivgation Bar label/Text Size, Color
To change Material You Navigation Bar labelTextStyle, you need to wrap NavigationBar with NavigationBarTheme & use data property with NavigationBarThemeData & then use labelTextStyle.
Check out below snipper code for better understanding
Hi Guys, Welcome to Proto Coders Point, In this flutter tutorial will learn how to get battery state & battery level (percentage) of a mobile device in flutter.
This package will give us battery level & Battery state:
Battery Level i.e. will get how much is battery percentage.
Battery State i.e will get BatteryState is FULL, CHARGING, DISCHARGING.
When is battery level checking useful in app
Sometimes, some important action in your app like background updates, let’s say the user doesn’t have enought battery percentage then this can lead to issues in performing background task like updates & if the phone is turning off during the process.
Depending on the battery level you can also maximize/minimize the performance, while the battery level is high/low, this can be especially used in games so if mobile device battery life is low then you can turn down the game performance.
Battery Plus can also be used to test how much the battery is been consumed during your flutter app is running.
Video Tutorial
Let’s get started with implementation
Step 1: Add battery plus dependencies
open pubspec.yaml file & under dependencies section add battery_plus package
dependencies:
battery_plus:
& hit pub get to download the package.
Step 2: import battery_plus.dart
Now, once you have added the dependencies into your flutter project to use it, you need to import battery_plus.dart class.
How to use it
Create instance of battery class
//instantiate it
var battery = Battery();
now you can use the battery instance object to get battery information.
Access battery percentage/level
battery.batterylevel
Get State of Battery
The below code will be listening to any changes in BatteryState.
It will keep track of batteryState, Weather the mobile is in charging, discharged or battery full. There is a callback method that return enum values:
BatteryState.charging.
BatteryState.discharging.
BatteryState.full.
battery.onBatteryStateChanged.listen((batteryState) { //here batteryState is Enum that can return this values: //BatteryState.charging. // BatteryState.discharging. // BatteryState.full. });
Complete Source – Flutter Battery Plus Example
In this flutter example, we willl fetch battery percentage level & also keep track, when mobile is into charging & when is removed from charging(discharging) and it will also alert or update you when battery is FULL.
Hi Guys, Welcome to Proto Coders Point. If you have upgraded your flutter SDK version to 2.5.0 you might been seeing a warning been shown on every widget that use static data to add ‘const’ modifier at the beginning on the widget.
This is because by default we now have the flutter_lints rules applied.
Video tutorial to remove const keyword requirement in flutter
How to remove const keyword requirement in flutter code
It is a good practive using the const keyword on any data type or widget that use static data.
However if you fill like removing it, you can edit your analysis_options.yaml file and add the following:
open analysis_option.yaml file & under linter > rules disable prefer_const_constructor.
linter:
rules:
prefer_const_constructors : false
Then, after making prefer const constructors: false, you need to run a command in IDE terminal as below
Hi Guys, Welcome to Proto Coders Point, In this flutter tutorial will learn how to share text, links, images, videos & files(pdf,doc) from your flutter app to another apps like whatsapp, facebook, Instagram…
Flutter share_plus package
To share content from our flutter app to another app, we make use of share_plus.
Share plus in flutter is a plugin for sharing app content such as text or files via the platform sharing UI, using ACTION_VIEW in Android & UIActivityViewController in iOS platform.
This share_plus package support all the platform like Android, iOS, macOS, Web, Linux and Windows.
Note: In Windows & Linus only Text sharing is supported using ‘mailto’, File sharing is not supported in windows & Linux.
Packages used in share files, Images, Text.
Share_plus: will help us in content sharing to another app.
http: used to download image from url (make network call).
path_provider: get the path where image is downloaded.
image_picker: user can pick image or video from galary or camera.
file_picker: helps us in picking any kind of files like pdf, doc, mp4, mp3 etc.
Therefore by using above package we will play with content to share them using share_plus plugin.
Video Tutorial on Share_Plus
Let’s get Started
Step 1: Add required dependencies
Open pubspec.yaml file and under dependencies section add below packages.
In Share plus package we have 2 method that let us in sharing content like text and files.
Text Sharing: Share.share(' your text message here ');
File Sharing: Share.shareFiles([path], text: 'Image Shared'); // here path is the location of file in your mobile directory.
1. Share Text Message with links to another app using share_plus
Here i have TextField & Button, user can enter text message in TextField & press on share button to share the text to another app for example like Whatsapp by using share_plus methods.
Here we will download image from a url using http package & store it into temporary directory & then get the path of downloaded image using path provider & share the image file using share_plus.
Image.network(imageurl),
ElevatedButton(
child: const Text('Share Image'),
onPressed: () async {
final imageurl = 'define your image url here';
final uri = Uri.parse(imageurl);
final response = await http.get(uri);
final bytes = response.bodyBytes;
final temp = await getTemporaryDirectory();
final path = '${temp.path}/image.jpg';
File(path).writeAsBytesSync(bytes);
await Share.shareFiles([path], text: 'Image Shared');
},
),
4. Pick image or video from galary or camera & share it