dual_screen 0.0.1-dev copy "dual_screen: ^0.0.1-dev" to clipboard
dual_screen: ^0.0.1-dev copied to clipboard

outdated

A new flutter plugin project.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:dual_screen/dual_screen.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _isDualScreenDevice = 'Unknown';
  String _isAppSpanned = 'Unknown';

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

  Future<void> _updateDualScreenInfo() async {
    String isDualDevice;
    String isAppSpanned;

    try {
      isDualDevice = (await DualScreen.isDualScreenDevice).toString();
    } on PlatformException catch (error) {
      isDualDevice =
          'Failed to determine dual device\nerror code: ${error.code}\nerror message: ${error.message}\nerror details: ${error.details}';
    }
    try {
      isAppSpanned = (await DualScreen.isAppSpanned).toString();
    } on PlatformException catch (error) {
      isAppSpanned =
          'Failed to determine if app is spanned\nerror code: ${error.code}\nerror message: ${error.message}\nerror details: ${error.details}';
    }

    if (!mounted) return;

    setState(() {
      _isDualScreenDevice = isDualDevice;
      _isAppSpanned = isAppSpanned;
    });
  }

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text('Dual screen device example'),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('Dual device: $_isDualScreenDevice'),
                SizedBox(height: 8),
                Text('App spanned: $_isAppSpanned'),
              ],
            ),
          ),
        ),
      );
}