LoginSignup
0
0

【Flutter】初心者が陥るBoxDecorationのエラー

Last updated at Posted at 2024-04-11

こんにちは。
今回は、flutter初心者の私がよく出していたErrorの解決方法を書きます。

  • エラー内容
    _AssertionError ('package:flutter/src/widgets/container.dart': Failed assertion: line 269 pos 15: 'color == null || decoration == null': Cannot provide both a color and a decoration To provide both, use "decoration: BoxDecoration(color: color)".)

これは、colorのプロパティがBoxDecorationの中に入っていない時に出ます。

方法

スクリーンショット 2023-08-13 20.18.51.png
colorプロパティはBoxDecorationの中に入れましょう

使用例

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Center(
          child: Container(
            width: 100,
            height: 70,
          //  color: Colors.pink, //これがダメ!!
            decoration: BoxDecoration(
            color:Colors.pink, //BoxDecorationの中に入れる
              border: Border.all(color: Colors.yellow),
            ),
          ),
        ));
  }
}

実行例

スクリーンショット 2024-04-11 9.47.13.png

最後に

ここまで読んでいただき、ありがとうございました!
いいねしてくれたら、スキップして喜びます:heartpulse:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0