Как передать две или более переменных в поток в шаблоне Bloccc в Flutter - PullRequest
0 голосов
/ 04 мая 2019

По сути, это все.например у меня есть этот код.

У меня есть этот код, в котором у меня есть текстовое поле и текст, текст меняется в зависимости от длины текстового поля, занимая шаблон блока, которого я достиг, что он выполняет свое назначение, но дополнительно мне нужно изменитьцвет текста.

Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    title: Text("TextField Example"),
  ),
  body: Container(
    margin: EdgeInsets.all(20.0),
    child: Center(
        child: Stack(
      children: <Widget>[
        Column(
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(top: 35.0),
              child: TextField(
                  controller: controller,
                  maxLines: 8,
                  decoration: InputDecoration(
                      hintText: "Escribe tu comentario",
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10),
                      )),
                  onChanged: (value) {
                    _chatTextfieldBloc.changeText(value);
                  }),
            ),
            Container(
                margin: EdgeInsets.only(top: 5),
                alignment: Alignment(-1, 0),
                child: StreamBuilder(
                  stream: _chatTextfieldBloc.textObservable,
                  builder: (BuildContext context, AsyncSnapshot snapshot) {
                    return Text(
                      snapshot.data,
                    );
                  },
                ))
          ],
        ),
        Positioned(
          right: 5.0,
          child: FloatingActionButton(
            backgroundColor: Colors.blueGrey,
            onPressed: () {
            },
            child: Icon(Icons.keyboard_arrow_right),
          ),
        ),
      ],
    )),
  ),
);
  }
}

в блоке:

class ChatTextfieldBloc {
  String initialText = "";
  int number = 12;

  BehaviorSubject<String> _subjectText;

  ChatTextfieldBloc({this.initialText}) {
    _subjectText = BehaviorSubject<String>.seeded(initialText);
  }

  Observable<String> get textObservable => _subjectText.stream;

  void changeText(String text) {



    if (text.length <= number) {
      initialText = "Te quedan ${number - text.length} caracteres";
    } else {
      initialText = "Te pasaste por ${(number - text.length) * -1} caracteres";
    }
    print(initialText);
    _subjectText.sink.add(initialText);
  }

  void dispose() {
    _subjectText.close();
  }
}

Мой вопрос заключается в том, как я могу передать две переменные, как вы сейчас видите в BeheaviorSubject. Я определил строкуя должен определить объект, который имеет обе переменные в качестве атрибута?Может ли он работать с объектом Map?

...