uni_platform 0.1.3 copy "uni_platform: ^0.1.3" to clipboard
uni_platform: ^0.1.3 copied to clipboard

Substitutes the Platform class, ensuring works across all platforms.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:uni_platform/uni_platform.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 _platformType = 'Unknown';

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

  Future<void> initPlatformState() async {
    String platformType;
    try {
      platformType = UniPlatform.select<String>(
        android: 'Android',
        fuchsia: 'Fuchsia',
        ios: 'iOS',
        linux: 'Linux',
        macos: 'macOS',
        windows: 'Windows',
        web: 'Web',
        otherwise: 'Unknown',
      );
    } on PlatformException {
      platformType = 'Failed to get platform type.';
    }

    if (!mounted) return;

    setState(() {
      _platformType = platformType;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformType\n'),
        ),
      ),
    );
  }
}
3
likes
160
pub points
81%
popularity

Publisher

verified publisherleanflutter.dev

Substitutes the Platform class, ensuring works across all platforms.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on uni_platform