Showing posts with label 【FLUTTER ANDROID STUDIO and IOS】Device Details. Show all posts
Showing posts with label 【FLUTTER ANDROID STUDIO and IOS】Device Details. Show all posts

Monday, May 31, 2021

【FLUTTER ANDROID STUDIO and IOS】Device Details

 import 'dart:io';

import 'package:device_info/device_info.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: DeviceDetailDemo(),
);
}
}

class DeviceDetailDemo extends StatefulWidget {


@override
_DeviceDetailDemoState createState() => _DeviceDetailDemoState();
}

class _DeviceDetailDemoState extends State<DeviceDetailDemo> {

String deviceName = '';
String deviceVersion = '';
String identifier = '';

Future<void> _deviceDetails() async {
final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
try {
if (Platform.isAndroid) {
var build = await deviceInfoPlugin.androidInfo;
setState(() {
deviceName = build.model;
deviceVersion = build.version.toString();
identifier = build.androidId;
});
//UUID for Android
} else if (Platform.isIOS) {
var data = await deviceInfoPlugin.iosInfo;
setState(() {
deviceName = data.name;
deviceVersion = data.systemVersion;
identifier = data.identifierForVendor;
}); //UUID for iOS
}
} on PlatformException {
print('Failed to get platform version');
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.redAccent[100],
title: Text("Flutter Device Details Demo"),
automaticallyImplyLeading: false,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
padding: EdgeInsets.all(14),
color: Colors.cyan[50],
onPressed: () {
_deviceDetails();
},
child: Text("Device Details",
style: TextStyle(color: Colors.black),),
),
deviceVersion.isNotEmpty && deviceName.isNotEmpty
&& identifier.isNotEmpty ?
Column(
children: [
SizedBox(height: 30,),
Text("Device Name:- " + deviceName, style: TextStyle
(color: Colors.red,
fontWeight: FontWeight.bold)),
SizedBox(height: 30,),
Text("Device Version:- " + deviceVersion,
style: TextStyle(color: Colors.red,
fontWeight: FontWeight.bold)),
SizedBox(height: 30,),
Text("Device Identifier:- " + identifier,
style: TextStyle(color: Colors.red,
fontWeight: FontWeight.bold)),
SizedBox(height: 30,),
],
) : Container(),
],
),
),
);
}
}

Rethinking Agri GTM

Discover why agribusiness growth depends on ecosystem coordination, not just sales - insights for founders, CEOs, and GTM leaders. ͏  ...