palette_from_wallpaper 0.1.5 copy "palette_from_wallpaper: ^0.1.5" to clipboard
palette_from_wallpaper: ^0.1.5 copied to clipboard

PlatformAndroid

An plugin for fetching the wallpaper palette on android

example/lib/main.dart

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

import 'package:palette_from_wallpaper/palette_from_wallpaper.dart';

void main() {
  runPlatformThemedApp(
    MyApp(),
    onError: (e) => PlatformPalette.errorHandler(primaryColor: Colors.red),
    initialOrFallback: () =>
        PlatformPalette.fallback(primaryColor: Colors.blue),
    startEagerly: true,
  );
}

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

class _MyAppState extends State<MyApp> {
  StreamSubscription? subscription;
  final scaffold = GlobalKey<ScaffoldState>();

  void dispose() {
    super.dispose();
    subscription?.cancel();
  }

  void _onPlatformUpdate(PlatformPalette palette) {
    if (!mounted) {
      return;
    }
    scaffold.currentState!
        .showSnackBar(SnackBar(content: Text('Updated theme!')));
  }

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

  // Platform messages are asynchronous, so we initialize in an async method.
  void initPlatformState() {
    try {
      subscription =
          PaletteFromWallpaper.paletteUpdates.listen(_onPlatformUpdate);
    } on Object {}
  }

  Widget square(Color? color) => Expanded(
        child: AspectRatio(
          aspectRatio: 1,
          child: Container(
            constraints: BoxConstraints.expand(),
            color: color,
            child: color == null ? Text('Unavailable') : null,
          ),
        ),
      );

  Widget palette(BuildContext context) => Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            children: [
              square(context.palette.primaryColor),
              square(context.palette.secondaryColor),
              square(context.palette.tertiaryColor),
            ],
            mainAxisSize: MainAxisSize.max,
          ),
          if (context.palette.colorHints != null) ...[
            Text('HINT_SUPPORTS_DARK_TEXT: '
                '${context.palette.colorHints! & PlatformPalette.HINT_SUPPORTS_DARK_TEXT}'),
            Text('HINT_SUPPORTS_DARK_THEME: '
                '${context.palette.colorHints! & PlatformPalette.HINT_SUPPORTS_DARK_THEME}'),
          ] else
            Text('No hints available'),
          Text('PaletteSource: ${context.palette.source}'),
        ],
      );

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: scaffold,
        appBar: AppBar(
          title: const Text('PaletteFromWallpaper Example'),
          backgroundColor: context.palette.primaryColor,
        ),
        body: Center(
          child: palette(context),
        ),
      ),
    );
  }
}
4
likes
145
points
5
downloads

Publisher

unverified uploader

Weekly Downloads

An plugin for fetching the wallpaper palette on android

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on palette_from_wallpaper

Packages that implement palette_from_wallpaper