Flutter device_type: The Essential Guide

Vinoth M
1 min readMar 4, 2024

Mar 05, 2024

Features

A new Flutter plugin is used to determine whether the device is a Phone, Phablet, Tablet, or a Larger Device like a Desktop.

Get started

To get started, add device_type to your pubspec.yaml. In this article we’ll be using ^0.0.6.

dependencies:
device_type: ^0.0.6

Depend on it #

Run this command:

With Flutter:

$ flutter pub add device_type

Configuration

After doing that let's add device_type configuration to your app:

import 'package:device_type/device_type.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
late String deviceType;

@override
void initState() {
super.initState();
}

String _getDeviceType(BuildContext context) {
return DeviceType.getDeviceType(context);
}

@override
Widget build(BuildContext context) {
deviceType = _getDeviceType(context);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin Device Type'),
),
body: Center(
child: Text('Running on: $deviceType\n'),
),
),
);
}
}

Find here the project example 👇🏿👇🏿

A simple Flutter project with sample code about how to work with device_type. To get…

https://pub.dev/packages/device_type

--

--