Agile & easy handler for device information 📱
Includes Device Info Plus ℹ️ and Connectivity Plus 🛜 implementations
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:
...
my_device: ^0.2.0In your library add the following import:
import 'package:my_device/my_device.dart';Once context is initialized, do the following to initialize the DeviceManager instance:
DeviceManager(context);You can also use the configure method to initialize the DeviceManager instance, responsive breakpoints and Connectivity configuration:
DeviceManager.configure(
context: context,
responsiveBreakpoints: const ResponsiveBreakpoints(
mobile: 400, //Default is 500
desktop: 1000, //Default is 900
),
connectivityConfigure: ConnectivityConfigure(
onConnectivityChanged: (connectivity) {
print('Connectivity changed: $connectivity');
},
onConnectionLost: () {
print('Connection lost');
},
onConnectionReestablished: () {
print('Connection reestablished');
},
useDefaultBehaviour: true // Shows a default toast when set to true
),
);
// Mobile view < mobile
// Tablet view > mobile && < desktop
// Desktop view > desktopfinal screenHeight = DeviceManager.screenHeight;
final screenWidth = DeviceManager.screenWidth;
final height = DeviceManager.height;
final width = DeviceManager.width;
final heightFromContext = context.height;
final widthFromContext = context.width;final isPhoneView = DeviceManager.isPhoneView; // width < mobile
final isTabletView = DeviceManager.isTabletView; // mobile <= width < desktop
final isDesktopView = DeviceManager.isDesktopView; // width >= desktopfinal isWeb = DeviceManager.isWeb;
final isAndroid = DeviceManager.isAndroid;
final isIOS = DeviceManager.isIOS;
final isMacOS = DeviceManager.isMacOS;
final isLinux = DeviceManager.isLinux;
final isWindows = DeviceManager.isWindows;
final platformName = DeviceManager.platformName;
final platformIcon = DeviceManager.platformIcon;final padding = DeviceManager.viewPadding;
final paddingFromContext = context.viewPadding;final connectivity = DeviceManager.connectivity;
final connectivityFromContext = context.connectivity;DeviceManager.listenConnectivityChanges();DeviceManager.onConnectionLost = () {
print('Connection lost');
};
DeviceManager.onConnectionReestablished = () {
print('Connection reestablished');
};
DeviceManager.onConnectivityChanged = (connectivity) {
print('Connectivity changed: $connectivity');
};final deviceInfo = DeviceManager.deviceInfo;This package assumes corresponding permissions depending on platform. Also take a look at the example app for further information.
