ブロックストリームが正しく更新されない

ビスクラヴレット

これは、ブロックアーキテクチャ「ゲッターxがnullで呼び出された」からの直接の続きです。@nonybrightoによって解決されました

現在の問題は、アプリケーションからエラーが発生しなくなったにもかかわらず、色が更新されていないためにロジックがどこかで失敗し、青色のままであるということです。私が呼び出す場合:colorBloc.changeColor(); 子(ドロップダウンメニュー)自体へのコールバックから、または親から直接、これらのウィジェットボタンの色を実際に更新することはありません。彼らはいつも青いです。

ボタンウィジェットを実際に更新するために追加で行う必要があることはありますか?

追加情報は必要ですか?

編集:親クラスと子クラス、およびブロックをどのように使用しようとしているのか。

dropdownmenu.dart

import 'package:flutter/material.dart';
import 'dart:math';
import 'package:ultimate_mtg/model/colorBloc.dart';
import 'package:ultimate_mtg/model/blocprovider.dart';

// ignore: camel_case_types
class dropDownMenu extends StatefulWidget {
  final Function() onPressed;
  final String tooltip;
  final IconData icon;
  final _callback;

  dropDownMenu({Key key, this.onPressed, this.tooltip, this.icon, @required void singlePlayerCallbacks(String callBackType), @required StatefulWidget styleMenu }  ):
      _callback = singlePlayerCallbacks;

  @override
  dropDownMenuState createState() => dropDownMenuState();
}

// ignore: camel_case_types
class dropDownMenuState extends State<dropDownMenu>
    with SingleTickerProviderStateMixin {
  bool isOpened = false;
  AnimationController _animationController;
  Animation<double> _translateButton;
  Curve _curve = Curves.easeOut;
  double _fabHeight = 58;
  double menuButtonSize = 55;
  Color menuButtonTheme;
  ColorBloc colorBloc = ColorBloc();

  @override
  initState() {
    _animationController =
    AnimationController(vsync: this, duration: Duration(milliseconds: 600))
      ..addListener(() {
        setState(() {});
      });
    _translateButton = Tween<double>(
      begin: 0.0,
      end: _fabHeight,
    ).animate(CurvedAnimation(
      parent: _animationController,
      curve: Interval(
        0.0,
        1.0,
        curve: _curve,
      ),
    ));
    super.initState();
  }

  @override
  dispose() {
    _animationController.dispose();
    colorBloc.dispose();
    super.dispose();
  }

  animate() {
    if (!isOpened) {
      _animationController.forward();
    } else {
      _animationController.reverse();
    }
    isOpened = !isOpened;
  }

  Widget backgroundColour() {
    return StreamBuilder(
      initialData: Colors.blue,
      stream: colorBloc.colorStream,
      builder: (BuildContext context, snapShot) => Container(
        width: menuButtonSize,
        height: menuButtonSize,
        child: RawMaterialButton(
          shape: CircleBorder(),
          fillColor: Colors.black,
          elevation: 5.0,
          onPressed: (){},
          child: Container(
            height: menuButtonSize - 3,
            width: menuButtonSize - 3,
            decoration: BoxDecoration(
              color: snapShot.data,
              shape: BoxShape.circle,
            ),
            child: Image.asset(
              'lib/images/background_colour.png',
              scale: 4,
            ),
          ),
        ),
      ),
    );
  }

  Widget toggle() {
    return Transform.rotate(
      angle: _animationController.value * (pi * 2),
      child: Container(
        width: menuButtonSize,
        height: menuButtonSize,
        child: RawMaterialButton(
          shape: CircleBorder(),
          fillColor: Colors.black,
          elevation: 5.0,
          onPressed: animate,
          child: SizedBox(
            height: menuButtonSize - 3,
            width: menuButtonSize - 3,
            child: Image.asset('lib/images/ic_launcher.png'),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget> [
        BlocProvider(
          bloc: ColorBloc(),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Stack(
                children: <Widget>[
                  Transform(
                    transform: Matrix4.translationValues(
                      0,
                      _translateButton.value,
                      0,
                    ),
                    child: backgroundColour(),
                  ),
                  toggle(),
                ],
              ),
            ],
          ),
        ),
        Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Container(
              height: menuButtonSize,
              width: menuButtonSize,
              child: Opacity(
                opacity: 0.0,
                child: FloatingActionButton(
                  heroTag: null,
                  onPressed: animate,
                ),
              ),
            ),
            SizedBox(
              height: 3.0,
            ),
            Container(
              height: menuButtonSize,
              width: menuButtonSize,
              child: Opacity(
                opacity: 0.0,
                child: FloatingActionButton(
                  heroTag: null,
                  onPressed:  isOpened == true? (){
                    widget?._callback('background');
                  } : () {},
                ),
              ),
            ),
          ],
        ),
      ],
    );
  }
}

singleplayer.dart

import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:ultimate_mtg/dropdownmenu.dart';
import 'package:ultimate_mtg/model/colorBloc.dart';

class SinglePlayerMode extends StatefulWidget {
  @override
  SinglePlayerModeParentState createState() => SinglePlayerModeParentState();
}

class SinglePlayerModeParentState extends State<SinglePlayerMode> {

  ColorBloc colorBloc = ColorBloc();

  @override
  void initState() {
    super.initState();
    SystemChrome.setEnabledSystemUIOverlays([]);
    SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,]);
    Screen.keepOn(true);
  }

  @override
  dispose() {
    colorBloc.dispose();
    super.dispose();
  }

  _changeColourButton() {
    colorBloc.changeColor();
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () => _exitApp(context),
      child: Scaffold(
        body: Container(
          child: Row(
            children: <Widget> [
              FloatingActionButton(
                backgroundColor: Colors.blue,
                heroTag: null,
                onPressed: _changeColourButton,
                child: Text(
                  'change',
                ),
              ),
              dropDownMenu(
                singlePlayerCallbacks: callBacks,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

それが基本的に私がやろうとしている方法です。

nonybrighto

コード内のコメントでいくつかの変更を加えました。動作することを確認するためにテストすることはできないので、試してみてください。

SinglePlayer.dart

import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:tv_series_jokes/blocs/bloc_provider.dart';
import 'package:ultimate_mtg/dropdownmenu.dart';
import 'package:ultimate_mtg/model/colorBloc.dart';

class SinglePlayerMode extends StatefulWidget {
  @override
  SinglePlayerModeParentState createState() => SinglePlayerModeParentState();
}

class SinglePlayerModeParentState extends State<SinglePlayerMode> {

  ColorBloc colorBloc = ColorBloc(); // our color bloc instance

  @override
  void initState() {
    super.initState();
    SystemChrome.setEnabledSystemUIOverlays([]);
    SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,]);
    Screen.keepOn(true);
  }

  @override
  dispose() {
    colorBloc.dispose();
    super.dispose();
  }

  _changeColourButton() {
    colorBloc.changeColor();
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () => _exitApp(context),
      child: Scaffold(
        body: BlocProvider<ColorBloc>( // DropDownMenu can now access the bloc with this
            bloc: colorBloc,
            child: Container(
          child: Row(
            children: <Widget> [
              FloatingActionButton(
                backgroundColor: Colors.blue,
                heroTag: null,
                onPressed: _changeColourButton,
                child: Text(
                  'change',
                ),
              ),
              dropDownMenu(
                singlePlayerCallbacks: callBacks,
              ),
            ],
          ),
        ),   
        ),
      ),
    );
  }
}  

DropDownMenu.dart

import 'package:flutter/material.dart';
import 'dart:math';
import 'package:ultimate_mtg/model/colorBloc.dart';
import 'package:ultimate_mtg/model/blocprovider.dart';

// ignore: camel_case_types
class dropDownMenu extends StatefulWidget {
  final Function() onPressed;
  final String tooltip;
  final IconData icon;
  final _callback;

  dropDownMenu({Key key, this.onPressed, this.tooltip, this.icon, @required void singlePlayerCallbacks(String callBackType), @required StatefulWidget styleMenu }  ):
      _callback = singlePlayerCallbacks;

  @override
  dropDownMenuState createState() => dropDownMenuState();
}

// ignore: camel_case_types
class dropDownMenuState extends State<dropDownMenu>
    with SingleTickerProviderStateMixin {
  bool isOpened = false;
  AnimationController _animationController;
  Animation<double> _translateButton;
  Curve _curve = Curves.easeOut;
  double _fabHeight = 58;
  double menuButtonSize = 55;
  Color menuButtonTheme;
  ColorBloc colorBloc; // we no longer create the instance here.

  @override
  initState() {
    _animationController =
    AnimationController(vsync: this, duration: Duration(milliseconds: 600))
      ..addListener(() {
        setState(() {});
      });
    _translateButton = Tween<double>(
      begin: 0.0,
      end: _fabHeight,
    ).animate(CurvedAnimation(
      parent: _animationController,
      curve: Interval(
        0.0,
        1.0,
        curve: _curve,
      ),
    ));


    colorBloc = BlocProvider.of<ColorBloc>(context); // Getting the color bloc from the widget tree
    super.initState();
  }

  @override
  dispose() {
    _animationController.dispose();
    super.dispose();
  }

  animate() {
    if (!isOpened) {
      _animationController.forward();
    } else {
      _animationController.reverse();
    }
    isOpened = !isOpened;
  }

  Widget backgroundColour() {
    return StreamBuilder(
      initialData: Colors.blue,
      stream: colorBloc.colorStream,
      builder: (BuildContext context, snapShot) => Container(
        width: menuButtonSize,
        height: menuButtonSize,
        child: RawMaterialButton(
          shape: CircleBorder(),
          fillColor: Colors.black,
          elevation: 5.0,
          onPressed: (){},
          child: Container(
            height: menuButtonSize - 3,
            width: menuButtonSize - 3,
            decoration: BoxDecoration(
              color: snapShot.data,
              shape: BoxShape.circle,
            ),
            child: Image.asset(
              'lib/images/background_colour.png',
              scale: 4,
            ),
          ),
        ),
      ),
    );
  }

  Widget toggle() {
    return Transform.rotate(
      angle: _animationController.value * (pi * 2),
      child: Container(
        width: menuButtonSize,
        height: menuButtonSize,
        child: RawMaterialButton(
          shape: CircleBorder(),
          fillColor: Colors.black,
          elevation: 5.0,
          onPressed: animate,
          child: SizedBox(
            height: menuButtonSize - 3,
            width: menuButtonSize - 3,
            child: Image.asset('lib/images/ic_launcher.png'),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {

    return Stack(
      children: <Widget> [
       // Removed the BlocProvider widget here. It wasn't working anything and was creating a separate bloc instance
       // I also see why you tried to make us of the blocprovider in the backgroundColour method and it gave null.Couldn't
       // have worked from that context.
       Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Stack(
                children: <Widget>[
                  Transform(
                    transform: Matrix4.translationValues(
                      0,
                      _translateButton.value,
                      0,
                    ),
                    child: backgroundColour(),
                  ),
                  toggle(),
                ],
              ),
            ],
        ),
        Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Container(
              height: menuButtonSize,
              width: menuButtonSize,
              child: Opacity(
                opacity: 0.0,
                child: FloatingActionButton(
                  heroTag: null,
                  onPressed: animate,
                ),
              ),
            ),
            SizedBox(
              height: 3.0,
            ),
            Container(
              height: menuButtonSize,
              width: menuButtonSize,
              child: Opacity(
                opacity: 0.0,
                child: FloatingActionButton(
                  heroTag: null,
                  onPressed:  isOpened == true? (){
                    widget?._callback('background');
                  } : () {},
                ),
              ),
            ),
          ],
        ),
      ],
    );
  }
}  

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

グローバル ポインター (リンク リストの先頭) が正しく更新されない

分類Dev

ブートストラップ 4 アルファ 6 ナビゲーションバーが Google クロームで正しく表示されない

分類Dev

マトリックスが正しく印刷されない

分類Dev

サムネイルがライトボックスギャラリーに正しく表示されない

分類Dev

フラッターブロックの状態が正しく更新されない

分類Dev

ブートストラップチェックボックスボタンが正しく表示されない

分類Dev

カスタムビットマップオブジェクトがPictureBoxに正しく表示されない

分類Dev

プロットヒストグラムが正しく表示されない

分類Dev

ブートストラップ4のドロップダウンが正しく配置されていない

分類Dev

SwiftUIリストがForEachで正しく更新されない

分類Dev

Javaマイクロストリームリストオブジェクトが正しく保存されていません

分類Dev

ブートストラップタブが正しくアクティブ化されない

分類Dev

高地のリクエストストリームが正しく渡されない

分類Dev

React-スクロール時にコンポーネントが正しく更新されない

分類Dev

ブートストラップグリッドが正しく位置合わせされていない

分類Dev

ブートストラップ4グリッドが正しく位置合わせされていない

分類Dev

Windows64ビットプログラムが正しくインストールされていない

分類Dev

Firefoxでのみブートストラップフォームが正しく表示されない

分類Dev

ブートストラップフォームラベルが正しく表示されない

分類Dev

Angular CLIMVCベースのプロジェクトでブートストラップが正しくロードされない理由

分類Dev

カスタムデータソースオブジェクトが正しく作成されない

分類Dev

pgAdminでロックされたジオメトリ列とビューアが正しく表示されない

分類Dev

ズームコントロールがマップ上で正しくレンダリングされない

分類Dev

ブートストラップサムネイルが正しく表示されない

分類Dev

ブートストラップグリッドの配置が正しく表示されない

分類Dev

Galaxy TabSでブートストラップグリッドが正しく表示されない

分類Dev

ブーストラップクラスが正しく解決されないのはなぜですか?

分類Dev

ClaudiaJSフレームワークでリクエストオブジェクトが正しく解析されない

分類Dev

ブートストラップグリッドアイテムが正しくレンダリングされない

Related 関連記事

  1. 1

    グローバル ポインター (リンク リストの先頭) が正しく更新されない

  2. 2

    ブートストラップ 4 アルファ 6 ナビゲーションバーが Google クロームで正しく表示されない

  3. 3

    マトリックスが正しく印刷されない

  4. 4

    サムネイルがライトボックスギャラリーに正しく表示されない

  5. 5

    フラッターブロックの状態が正しく更新されない

  6. 6

    ブートストラップチェックボックスボタンが正しく表示されない

  7. 7

    カスタムビットマップオブジェクトがPictureBoxに正しく表示されない

  8. 8

    プロットヒストグラムが正しく表示されない

  9. 9

    ブートストラップ4のドロップダウンが正しく配置されていない

  10. 10

    SwiftUIリストがForEachで正しく更新されない

  11. 11

    Javaマイクロストリームリストオブジェクトが正しく保存されていません

  12. 12

    ブートストラップタブが正しくアクティブ化されない

  13. 13

    高地のリクエストストリームが正しく渡されない

  14. 14

    React-スクロール時にコンポーネントが正しく更新されない

  15. 15

    ブートストラップグリッドが正しく位置合わせされていない

  16. 16

    ブートストラップ4グリッドが正しく位置合わせされていない

  17. 17

    Windows64ビットプログラムが正しくインストールされていない

  18. 18

    Firefoxでのみブートストラップフォームが正しく表示されない

  19. 19

    ブートストラップフォームラベルが正しく表示されない

  20. 20

    Angular CLIMVCベースのプロジェクトでブートストラップが正しくロードされない理由

  21. 21

    カスタムデータソースオブジェクトが正しく作成されない

  22. 22

    pgAdminでロックされたジオメトリ列とビューアが正しく表示されない

  23. 23

    ズームコントロールがマップ上で正しくレンダリングされない

  24. 24

    ブートストラップサムネイルが正しく表示されない

  25. 25

    ブートストラップグリッドの配置が正しく表示されない

  26. 26

    Galaxy TabSでブートストラップグリッドが正しく表示されない

  27. 27

    ブーストラップクラスが正しく解決されないのはなぜですか?

  28. 28

    ClaudiaJSフレームワークでリクエストオブジェクトが正しく解析されない

  29. 29

    ブートストラップグリッドアイテムが正しくレンダリングされない

ホットタグ

アーカイブ