devicetheme 1.1.0 copy "devicetheme: ^1.1.0" to clipboard
devicetheme: ^1.1.0 copied to clipboard

A Flutter package to read and return the device theme and set app theme.

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  String _themeName = 'unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String themeName;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      //await Devicetheme.setAppTheme('light');
      themeName = await Devicetheme.platformTheme;
    } on PlatformException catch (exception) {
      print(exception);
      themeName = 'Failed to get theme name.';
    }

    // 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(() {
      _themeName = themeName;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Device Theme Example'),
        ),
        body: Center(
          child: Text('Running on: $_themeName\n'),
        ),
      ),
    );
  }
}
1
likes
40
pub points
0%
popularity

Publisher

verified publishereastglint.com

A Flutter package to read and return the device theme and set app theme.

Repository (GitHub)
View/report issues

License

Apache-2.0 (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on devicetheme