kiosk_mode 0.5.1 copy "kiosk_mode: ^0.5.1" to clipboard
kiosk_mode: ^0.5.1 copied to clipboard

Plugin for working with Lock Task / Guided Access modes.

example/lib/main.dart

import 'dart:io';

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

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

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: const Center(child: _Home()),
        ),
      );
}

class _Home extends StatefulWidget {
  const _Home();

  @override
  State<_Home> createState() => _HomeState();
}

class _HomeState extends State<_Home> {
  late final Stream<KioskMode> _currentMode = watchKioskMode();

  void _showSnackBar(String message) => ScaffoldMessenger.of(context)
      .showSnackBar(SnackBar(content: Text(message)));

  void _handleStart(bool didStart) {
    if (!didStart && Platform.isIOS) {
      _showSnackBar(
        'Single App mode is supported only for devices that are supervised'
        ' using Mobile Device Management (MDM) and the app itself must'
        ' be enabled for this mode by MDM.',
      );
    }
  }

  void _handleStop(bool? didStop) {
    if (didStop == false) {
      _showSnackBar(
        'Kiosk mode could not be stopped or was not active to begin with.',
      );
    }
  }

  @override
  Widget build(BuildContext context) => StreamBuilder(
        stream: _currentMode,
        builder: (context, snapshot) {
          final mode = snapshot.data;
          final message = mode == null
              ? 'Can\'t determine the mode'
              : 'Current mode: $mode';

          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              MaterialButton(
                onPressed: switch (mode) {
                  null || KioskMode.enabled => null,
                  KioskMode.disabled => () =>
                      startKioskMode().then(_handleStart)
                },
                child: const Text('Start Kiosk Mode'),
              ),
              MaterialButton(
                onPressed: switch (mode) {
                  null || KioskMode.disabled => null,
                  KioskMode.enabled => () => stopKioskMode().then(_handleStop),
                },
                child: const Text('Stop Kiosk Mode'),
              ),
              MaterialButton(
                onPressed: () => isManagedKiosk()
                    .then((isManaged) => 'Kiosk is managed: $isManaged')
                    .then(_showSnackBar),
                child: const Text('Check if managed'),
              ),
              MaterialButton(
                onPressed: () => getKioskMode()
                    .then((mode) => 'Kiosk mode: $mode')
                    .then(_showSnackBar),
                child: const Text('Check mode'),
              ),
              Text(message),
            ],
          );
        },
      );
}
86
likes
150
pub points
92%
popularity

Publisher

verified publishermews.com

Plugin for working with Lock Task / Guided Access modes.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, stream_transform

More

Packages that depend on kiosk_mode