my_device 0.0.4 my_device: ^0.0.4 copied to clipboard
Agile and easy access to device information and internet connection alerts
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:my_device/my_device.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'my_Device',
theme: ThemeData(
primarySwatch: Colors.deepPurple,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({
Key? key,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
Device(context, assetBackground: 'assets/background.png');
var deviceInfo = Device.i.deviceInfo;
var device = Device.instance.mediaQuery;
var screenHeigth = Device.i.screenHeigth;
var screenWidth = Device.i.screenWidth;
var backgroundAssetPath = Device.i.backgroundAssetPath;
var padding = Device.i.viewPadding;
var webDevice = Device.i.isWeb;
var androidDevice = Device.i.isAndroid;
var iosDevice = Device.i.isIOS;
return Scaffold(
appBar: AppBar(
title: const Text('My device'),
leading: Padding(
padding: const EdgeInsets.only(left: 30),
child: Row(
children: [
if (androidDevice)
const Icon(
Icons.android_rounded,
color: Colors.white,
),
if (iosDevice) const Text('IOS'),
if (webDevice) const Text('Web'),
],
),
),
),
backgroundColor: Color(0xFF040029),
body: Stack(
children: <Widget>[
Padding(padding: padding),
Text(deviceInfo),
Text('Device Pixel Ratio: ' + device.devicePixelRatio.toString()),
Center(child: Image.asset(backgroundAssetPath)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
width: screenWidth / 2.3,
height: screenHeigth / 2.6,
child: Card(
color: Colors.teal.withOpacity(.96),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
),
),
SizedBox(
width: screenWidth / 2.3,
height: screenHeigth / 2.6,
child: Card(
color: Colors.amber[700]!.withOpacity(.96),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
),
),
],
),
],
),
);
}
}