Skip to content

Commit

Permalink
chore(device_info_plus): Refactor example app (#1855)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuberen committed May 25, 2023
1 parent 1463bea commit 71b5052
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
73 changes: 36 additions & 37 deletions packages/device_info_plus/device_info_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import 'dart:async';
import 'dart:developer' as developer;
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -45,19 +44,21 @@ class _MyAppState extends State<MyApp> {
if (kIsWeb) {
deviceData = _readWebBrowserInfo(await deviceInfoPlugin.webBrowserInfo);
} else {
if (Platform.isAndroid) {
deviceData =
_readAndroidBuildData(await deviceInfoPlugin.androidInfo);
} else if (Platform.isIOS) {
deviceData = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo);
} else if (Platform.isLinux) {
deviceData = _readLinuxDeviceInfo(await deviceInfoPlugin.linuxInfo);
} else if (Platform.isMacOS) {
deviceData = _readMacOsDeviceInfo(await deviceInfoPlugin.macOsInfo);
} else if (Platform.isWindows) {
deviceData =
_readWindowsDeviceInfo(await deviceInfoPlugin.windowsInfo);
}
deviceData = switch (defaultTargetPlatform) {
TargetPlatform.android =>
_readAndroidBuildData(await deviceInfoPlugin.androidInfo),
TargetPlatform.iOS =>
_readIosDeviceInfo(await deviceInfoPlugin.iosInfo),
TargetPlatform.linux =>
_readLinuxDeviceInfo(await deviceInfoPlugin.linuxInfo),
TargetPlatform.windows =>
_readWindowsDeviceInfo(await deviceInfoPlugin.windowsInfo),
TargetPlatform.macOS =>
_readMacOsDeviceInfo(await deviceInfoPlugin.macOsInfo),
TargetPlatform.fuchsia => <String, dynamic>{
'Error:': 'Fuchsia platform isn\'t supported'
},
};
}
} on PlatformException {
deviceData = <String, dynamic>{
Expand Down Expand Up @@ -222,21 +223,7 @@ class _MyAppState extends State<MyApp> {
),
home: Scaffold(
appBar: AppBar(
title: Text(
kIsWeb
? 'Web Browser info'
: Platform.isAndroid
? 'Android Device Info'
: Platform.isIOS
? 'iOS Device Info'
: Platform.isLinux
? 'Linux Device Info'
: Platform.isMacOS
? 'MacOS Device Info'
: Platform.isWindows
? 'Windows Device Info'
: '',
),
title: Text(_getAppBarTitle()),
elevation: 4,
),
body: ListView(
Expand All @@ -245,7 +232,7 @@ class _MyAppState extends State<MyApp> {
return Row(
children: <Widget>[
Container(
padding: const EdgeInsets.all(10.0),
padding: const EdgeInsets.all(10),
child: Text(
property,
style: const TextStyle(
Expand All @@ -254,14 +241,15 @@ class _MyAppState extends State<MyApp> {
),
),
Expanded(
child: Container(
padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
child: Text(
'${_deviceData[property]}',
maxLines: 10,
overflow: TextOverflow.ellipsis,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Text(
'${_deviceData[property]}',
maxLines: 10,
overflow: TextOverflow.ellipsis,
),
),
)),
),
],
);
},
Expand All @@ -270,4 +258,15 @@ class _MyAppState extends State<MyApp> {
),
);
}

String _getAppBarTitle() => kIsWeb
? 'Web Browser info'
: switch (defaultTargetPlatform) {
TargetPlatform.android => 'Android Device Info',
TargetPlatform.iOS => 'iOS Device Info',
TargetPlatform.linux => 'Linux Device Info',
TargetPlatform.windows => 'Windows Device Info',
TargetPlatform.macOS => 'MacOS Device Info',
TargetPlatform.fuchsia => 'Fuchsia Device Info',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXAggregateTarget section */
Expand Down Expand Up @@ -203,7 +203,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "The Flutter Authors";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down Expand Up @@ -256,6 +256,7 @@
/* Begin PBXShellScriptBuildPhase section */
3399D490228B24CF009A79C7 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -405,7 +406,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -488,7 +489,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -535,7 +536,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ flutter:
uses-material-design: true

environment:
sdk: '>=2.18.0 <4.0.0'
sdk: '>=3.0.0 <4.0.0'

0 comments on commit 71b5052

Please sign in to comment.