get_settings 1.0.6 copy "get_settings: ^1.0.6" to clipboard
get_settings: ^1.0.6 copied to clipboard

Toolbox, some useful methods, not commonly used but indispensable

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:get_settings/getsettings.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> {
  String platformVersion = 'Unknown';
  String isPad = 'Unknown';
  String isiOSAppOnMac = 'Unknown';
  String getUserAgent = 'Unknown';
  String getCPUType = 'Unknown';
  String getRotationOn = 'Unknown';
  final _getsettingsPlugin = GetSettings();

  @override
  void initState() {
    super.initState();
    _getsettingsPlugin.onListenSettings((status1) {
      initPlatformState();
      setState(() {});
    }, (onError) {
      if (kDebugMode) {
        print('error:$onError');
      }
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    platformVersion = await _getsettingsPlugin.getPlatformVersion() ??
        'Unknown platform version';
    isPad = (await _getsettingsPlugin.isPad()).toString();
    isiOSAppOnMac = (await _getsettingsPlugin.isiOSAppOnMac()).toString();
    getUserAgent = (await _getsettingsPlugin.getUserAgent())!;
    getCPUType = (await _getsettingsPlugin.getCPUType())!;
    getRotationOn = (await _getsettingsPlugin.isRotationOn()).toString();
  }

  @override
  Widget build(BuildContext context) {
    Future.delayed(const Duration(seconds: 1), () {
      initPlatformState();
      setState(() {});
    });
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('isPad:$isPad'),
              Text('PlatformVersion:$platformVersion'),
              Text('isiOSAppOnMac:$isiOSAppOnMac'),
              Text('getUserAgent:$getUserAgent'),
              Text('getCPUType:$getCPUType'),
              Text('getRotationOn:$getRotationOn'),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async {
            initPlatformState();
            setState(() {});
          },
          child: const Text('Test'),
        ),
      ),
    );
  }
}
1
likes
160
points
416
downloads

Publisher

verified publisherdev.sumsg.com

Weekly Downloads

Toolbox, some useful methods, not commonly used but indispensable

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on get_settings