ubuntu / archive_yaru.dart

Ubuntu Yaru Flutter Theme
https://ubuntu.github.io/yaru.dart/
Mozilla Public License 2.0
335 stars 40 forks source link

YaruTheme accent color initialization #231

Closed jpnurmi closed 1 year ago

jpnurmi commented 1 year ago

Determining the system accent color is an asynchronous operation that may take a noticeable amount of time.

When the system has a non-default accent color, the default orange accent color may sometimes be visible for a short glimpse until the system accent color has been resolved and communicated over the platform channel.

The problem is usually most visible with more complex UIs but is even reproducible with such a minimal test case:

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

void main() {
  runApp(YaruTheme(
    builder: (context, yaru, child) => MaterialApp(
      theme: yaru.theme,
      darkTheme: yaru.darkTheme,
      home: Builder(
        builder: (context) => Scaffold(
          backgroundColor: Theme.of(context).primaryColor,
          appBar: AppBar(title: const Text('Yaru')),
        ),
      ),
    ),
  ));
}

We could add something like YaruTheme.ensureInitialized() that can be called and awaited on startup. Alternatively, we could hide the logic inside YaruTheme and build an empty widget until the information arrives.

Jupi007 commented 1 year ago

I like the idea of build an empty widget until accent is initialized :+1: