質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Flutter

Flutterは、iOSとAndroidのアプリを同じコードで開発するためのフレームワークです。オープンソースで開発言語はDart。双方のプラットフォームにおける高度な実行パフォーマンスと開発効率を提供することを目的としています。

Dart

Dartは、Googleによって開発されたJavaScriptの代替となることを目的に作られた、ウェブ向けのプログラミング言語である。

Android Widget

ホームスクリーンウィジェット、またはAndroidアプリケーションのスクリーン上で使用される一般的なユーザインタフェース要素に関連することを指します。

Q&A

1回答

2113閲覧

FlutterのWidgetについての質問です。

toomooyaa

総合スコア0

Flutter

Flutterは、iOSとAndroidのアプリを同じコードで開発するためのフレームワークです。オープンソースで開発言語はDart。双方のプラットフォームにおける高度な実行パフォーマンスと開発効率を提供することを目的としています。

Dart

Dartは、Googleによって開発されたJavaScriptの代替となることを目的に作られた、ウェブ向けのプログラミング言語である。

Android Widget

ホームスクリーンウィジェット、またはAndroidアプリケーションのスクリーン上で使用される一般的なユーザインタフェース要素に関連することを指します。

0グッド

0クリップ

投稿2021/12/28 13:41

解決したいこと

Flutter初学者です。質問です。
ContainerでFloatingActionButtonのサイズなどを決め、AnimatedContainerで色を変えるということをしたいのですが、ContainerとAnimatedContainerを併用できません。

どこでchildやchildrenを使うなどのWidgetの関係性?のようなものがわかりません。
どなたか回答よろしくお願いします。

発生している問題・エラー

Positional arguments must occur before named arguments. Too many positional arguments: 0 expected, but 1 found. Expected to find ')

該当するソースコード

Dart

1floatingActionButton: Container( 2 margin: EdgeInsets.only(bottom: 180.0,right:130.0), 3 width: 100.0, 4 height: 100.0, 5 child: FloatingActionButton( 6 onPressed: _incrementCounter, 7 tooltip: 'Increment', 8 child: const Icon(Icons.add), 9 ) 10 ), 11 AnimatedContainer( 12 duration: Duration(seconds: 5), 13 color: Color(0xFF0000FF); 14 ), 15 ); (これはScaffoldです。)

自分で試したこと

Expected to find ')'. ➡ 「)」がもしかしたら足りないのかと思い、追加したりしました。

containerとAnimatedcontainerの位置を逆にしたり、Centerの中にContainerとAnimatedContainerを入れました。

AnimatedContainerを
child: AnimatedContainer(.......
children: <Widget> [.......
にしました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

children

2021/12/30 14:00

コード全体を見せていただけませんか?
toomooyaa

2021/12/31 04:35

お願いします。 import 'package:flutter/material.dart'; void main() { runApp(const aaa()); } class aaa extends StatelessWidget { const aaa({Key? key}) : super(key: key); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.brown, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); // This widget is the home page of your application. It is stateful, meaning // that it has a State object (defined below) that contains fields that affect // how it looks. // This class is the configuration for the state. It holds the values (in this // case the title) provided by the parent (in this case the App widget) and // used by the build method of the State. Fields in a Widget subclass are // always marked "final". final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; void _incrementCounter() { setState(() { // This call to setState tells the Flutter framework that something has // changed in this State, which causes it to rerun the build method below // so that the display can reflect the updated values. If we changed // _counter without calling setState(), then the build method would not be // called again, and so nothing would appear to happen. _counter++; }); } @override Widget build(BuildContext context) { // This method is rerun every time setState is called, for instance as done // by the _incrementCounter method above. // // The Flutter framework has been optimized to make rerunning build methods // fast, so that you can just rebuild anything that needs updating rather // than having to individually change instances of widgets. return Scaffold( appBar: AppBar( // Here we take the value from the MyHomePage object that was created by // the App.build method, and use it to set our appbar title. title: Center(child: Text("連打計測")), ), body: Center( // Center is a layout widget. It takes a single child and positions it // in the middle of the parent. child: Column( // Column is also a layout widget. It takes a list of children and // arranges them vertically. By default, it sizes itself to fit its // children horizontally, and tries to be as tall as its parent. // // Invoke "debug painting" (press "p" in the console, choose the // "Toggle Debug Paint" action from the Flutter Inspector in Android // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) // to see the wireframe for each widget. // // Column has various properties to control how it sizes itself and // how it positions its children. Here we use mainAxisAlignment to // center the children vertically; the main axis here is the vertical // axis because Columns are vertical (the cross axis would be // horizontal). mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ const Text( '右下のボタンをたくさん押してください', ), Text( '$_counter', style: Theme.of(context).textTheme.headline4, ), ], ), ), floatingActionButton: Container( margin: EdgeInsets.only(bottom: 180.0,right:130.0), width: 100.0, height: 100.0, child: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', child: const Icon(Icons.add), ) ), AnimatedContainer( duration: Duration(seconds: 5), color: Color(0xFF0000FF); ), ); } }
guest

回答1

0

FloatingActionButtonの色を変えるには FloatingActionButtonのbackgroundColorプロパティで変える必要があります。
(赤にする場合)

dart

1Container( 2 margin: EdgeInsets.only(bottom: 180.0, right: 130.0), 3 width: 100.0, 4 height: 100.0, 5 child: FloatingActionButton( 6 backgroundColor: Colors.red, 7 onPressed: _incrementCounter, 8 tooltip: 'Increment', 9 child: const Icon(Icons.add), 10 )),

しかし、 FloatingActionButtonの色を変えてもアニメーションされません。
AnimtedThemeなどを使う必要があると思います。

dart

1 AnimatedTheme( 2 duration: Duration(milliseconds: 500), 3 data: Theme.of(context).copyWith( 4 floatingActionButtonTheme: FloatingActionButtonThemeData( 5 backgroundColor: Colors.blue,//ここ変えると色がアニメーションされる。 6 ), 7 ), 8 child: Container( 9 margin: EdgeInsets.only(bottom: 180.0, right: 130.0), 10 width: 100.0, 11 height: 100.0, 12 child: FloatingActionButton( 13 onPressed: _incrementCounter, 14 tooltip: 'Increment', 15 child: const Icon(Icons.add), 16 )), 17 ),

投稿2021/12/31 13:01

編集2021/12/31 22:34
children

総合スコア89

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

toomooyaa

2021/12/31 15:48

明けましておめでとうございます。 body:AnimatedContainer・・・と打ったら、きちんとFloatingActionButtonが変化するのでしょうか?
children

2021/12/31 22:35

明けましておめでとうございます。 すいません。 根本的な解決方法を書いていませんでした。 もう一度回答を確認してみて下さい。
toomooyaa

2022/01/01 04:16

解決方法ありがとうございます。 AnimatedContainerでFloatingActionButtonの色やサイズを変えることは不可能ということでしょうか?
children

2022/01/01 11:53

サイズは可能ですが色は変えられません。
toomooyaa

2022/01/01 15:43

Containerは色変えれるのにAnimatedContainerは色が変えられなくてややこしいですね...
toomooyaa

2022/01/01 15:49

このコードで実行したらエラーは出なかったのですが、色が赤のままになってしまいます。 そして、child: FloatingActionButton()とchild: AnimatedContainerの位置を逆にするとAnimatedThemeに、「The named parameter 'child' is required, but there's no corresponding argument.」というエラーが出てしまいます。 floatingActionButton: Container( margin: EdgeInsets.only(bottom: 180.0,right:130.0), width: 100.0, height: 100.0, child: AnimatedTheme( duration: Duration(milliseconds: 500), data: Theme.of(context).copyWith( floatingActionButtonTheme: FloatingActionButtonThemeData( backgroundColor: Colors.blue, ), ), child: FloatingActionButton( backgroundColor: Colors.red, onPressed: _incrementCounter, tooltip: 'Increment', ), ), ), ); これが逆にしたときのコードです。 floatingActionButton: Container( margin: EdgeInsets.only(bottom: 180.0,right:130.0), width: 100.0, height: 100.0, child: FloatingActionButton( backgroundColor: Colors.red, onPressed: _incrementCounter, tooltip: 'Increment', child: AnimatedTheme( duration: Duration(milliseconds: 500), data: Theme.of(context).copyWith( floatingActionButtonTheme: FloatingActionButtonThemeData( backgroundColor: Colors.blue, ), ), ), ), ), ); なぜでしょうか?
children

2022/01/01 23:19 編集

Containerは色変えれるのにAnimatedContainerは色が変えられない→とにかくそういうことではなく、FloatingActionButtonの色は基本的にFloatingActionButtonのbackgroundColorプロパティでしか変えられないです。 色が赤のままになってしまいます→色の値を変えるコードを書かないといけません。 そして、child: FloatingActionButton()とchild: AnimatedContainerの位置を逆にするとAnimatedThemeに、「The named parameter 'child' is required, but there's no corresponding argument.」というエラーが出てしまいます→AnimatedThemeはそのchildのwidgetの色などをアニメーションさせて変更できるというwidgetですので順番は変えてはいけません。
toomooyaa

2022/01/02 05:51

FloatingActionButtonのbackgroundColorプロパティでしか変えられないです。 <そういうことですが、ありがとうございます! 色が赤のままになってしまいます→色の値を変えるコードを書かないといけません。 <AnimadedContainerの・・・backgroundColorをいじれば変わるわけではないのでしょうか? AnimatedThemeはそのchildのwidgetの色などをアニメーションさせて変更できるというwidgetですので順番は変えてはいけません。 <そのchildというのはここでいう、child: FloatingActionButtonのことでしょうか? (多くの質問をしてしまい、申し訳ございません。)
children

2022/01/04 13:02

返信おそくてすいません AnimadedContainerの・・・backgroundColorをいじれば変わるわけではないのでしょうか?→とにかくAnimadedThemeかFloatingActionButtonのbackgroundColorをいじればFloatingActionButtonの色が変わります。 そのchildというのはここでいう、child: FloatingActionButtonのことでしょうか?→そのとおりです
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問