android_system_properties 1.0.0 copy "android_system_properties: ^1.0.0" to clipboard
android_system_properties: ^1.0.0 copied to clipboard

PlatformAndroid

Flutter package to get android system properties

example/lib/main.dart

import 'dart:async';

import 'package:android_system_properties/android_system_properties.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _systemProperties = 'Unknown';
  final _androidSystemPropertiesPlugin = AndroidSystemProperties();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion = await _androidSystemPropertiesPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> getSystemProperties() async {
    String systemProperties;
    try {
      systemProperties = await _androidSystemPropertiesPlugin.getSystemProperties('ro.build.version.sdk') ??
          'Unknown system properties';
    } on PlatformException {
      systemProperties = 'Failed to get system properties.';
    }
    if (!mounted) return;
    setState(() {
      _systemProperties = systemProperties;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [Text('Running on: $_platformVersion\n'), Text('System properties: $_systemProperties\n')],
          ),
        ),
      ),
    );
  }
}
2
likes
140
points
368
downloads

Publisher

verified publisherdashtoon.com

Weekly Downloads

Flutter package to get android system properties

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on android_system_properties