stack widget code example

Example 1: flutter stack imagge on top center of card

Stack(
  children: <Widget>[
    Card(
      margin: const EdgeInsets.only(top: 20.0),
      child: SizedBox(
          height: 100.0,
          width: double.infinity,
          child: Padding(
            padding: const EdgeInsets.only(top: 45.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Text(
                  "Foo",
                  style: Theme.of(context).textTheme.subhead,
                ),
                Text("bar")
              ],
            ),
          )),
    ),
    Positioned(
      top: .0,
      left: .0,
      right: .0,
      child: Center(
        child: CircleAvatar(
          radius: 30.0,
          child: Text("D"),
        ),
      ),
    )
  ],
),

Example 2: how to make stack not float in flutter

bool isKeyboardVisible = false;

  @override
  void initState() {
    super.initState();

    KeyboardVisibilityNotification().addNewListener(
      onChange: (bool visible) {
        isKeyboardVisible = visible;
      },
    );
  }

Tags:

Misc Example