web-dev-qa-db-fra.com

Flutter - Le changement de couleur de la barre d’application ne fonctionne pas

J'essaie de changer la couleur d'arrière-plan de AppBar mais cela ne fonctionne pas.

Lorsque vous choisissez la couleur 0x673AB7 en fonction de l'image ci-dessous, AppBar devient gris au lieu de violet.

import "package:flutter/material.Dart";

void main() {
  runApp(new ControlleApp());
}

class ControlleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: "Controlle Financeiro",
      home: new HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        backgroundColor: new Color(0x673AB7),
      ),
    );
  }
}

 enter image description here

5
rafaelcb21

On dirait que ta couleur est complètement transparente. Essayez de changer la couleur en 0xFF673AB7

5
Randal Schwartz

Comme @Randal l'a mentionné, vous utilisez le code hexadécimal sans valeur alpha. Si vous ne le spécifiez pas, la transparence sera totale. Vous pouvez donc utiliser les deux premières valeurs comme alpha et les six autres comme RVB.

Consultez le code source de la classe Color. Il y a un commentaire comme ci-dessous:

  /// Construct a color from the lower 32 bits of an [int].
  ///
  /// The bits are interpreted as follows:
  ///
  /// * Bits 24-31 are the alpha value.
  /// * Bits 16-23 are the red value.
  /// * Bits 8-15 are the green value.
  /// * Bits 0-7 are the blue value.
  ///
  /// In other words, if AA is the alpha value in hex, RR the red value in hex,
  /// GG the green value in hex, and BB the blue value in hex, a color can be
  /// expressed as `const Color(0xAARRGGBB)`.
  ///
  /// For example, to get a fully opaque orange, you would use `const
  /// Color(0xFFFF9000)` (`FF` for the alpha, `FF` for the red, `90` for the
  /// green, and `00` for the blue).
1
Blasanka