data_saver 0.3.0 copy "data_saver: ^0.3.0" to clipboard
data_saver: ^0.3.0 copied to clipboard

Simple Flutter plugin to check the current Data Saver/Low Data Mode.

example/lib/main.dart

import 'dart:async';

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

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

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

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

class _MyAppState extends State<MyApp> {
  DataSaverMode? _dataSaverMode;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initDataSaver() async {
    const dataSaver = DataSaver();
    final dataSaverMode = await dataSaver.checkMode();

    // 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(() {
      _dataSaverMode = dataSaverMode;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('data_saver example app'),
        ),
        body: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 12),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Text(
                'Current data saver mode: ${_dataSaverMode?.name}',
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: 24),
              ElevatedButton.icon(
                onPressed: initDataSaver,
                icon: const Icon(Icons.refresh),
                label: const Text('Refresh'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
4
likes
160
pub points
51%
popularity

Publisher

verified publishernikodembernat.com

Simple Flutter plugin to check the current Data Saver/Low Data Mode.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on data_saver