'Flutter, How to fit width in Column to first child
This is my code .
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.5),
child: (message.caption != null)
? Column(
children: [
Flexible(
child: ImageLoader(message: message, controller: _),
),
Container(
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: BubbleText(
message: message,
fromCaption: true,
account: account),
),
),
],
)
: ...
This is what my column looks like with 2 children

Here is how I want it to look

Solution 1:[1]
It actually amazes me how often does this need arise and how no one has wrote a package about this yet.
So I did: https://pub.dev/packages/flex_with_main_child
It'll look something like this:
ColumnWithMainChild(
mainChild: Flexible(
child: ImageLoader(message: message, controller: _),
),
childrenBelow: [
Container(
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: BubbleText(
message: message,
fromCaption: true,
account: account),
),
),
],
)
Solution 2:[2]
You do not need to convert an Observable into a Promise at all.
You can trigger the execution of an Observable with the submit method and you can concatenate the execution of several Observable with the concatMap operator.
So, for instance, if you have 3 APIs which you want to execute one after the other and you need the result of the previous API to be used as parameter in the subsequent API, you can use some code like this
api_1() // returns an Observable
.pipe(
concatMap(result_1 => {
return api_2(result_1) // api_2 returns an Observable
}),
concatMap(result_2 => {
return api_3(result_2) // api_2 returns an Observable
})
)
.subscribe({ // subscribe triggers the execution
next: result_3 => {// do something with result_3},
error: err => {// handle the error condition},
complete: () => {// do something, if you need, when the Observable completes}
})
The object passed to the subscribe method as parameter is the Observer.
You can read more details on how to use Observables with APIs in this article
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shuang Li |
| Solution 2 | Picci |
