Ask Your Question
3

What is the process of making a floating widget background in Flutter/Dart?

asked 2023-06-22 23:45:47 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-23 00:03:01 +0000

pufferfish gravatar image

To make a floating widget background in Flutter/Dart, you can follow these steps:

  1. Create a scaffold widget and add a stack widget to it.
Scaffold(
  body: Stack(
    children: [
      // Your widgets here
    ],
  ),
);
  1. Add a container widget to the stack and give it a color.
Scaffold(
  body: Stack(
    children: [
      Container(
        color: Colors.blue.withOpacity(0.5),
      ),
      // Your widgets here
    ],
  ),
);
  1. Make the container widget as tall as the screen height by using MediaQuery.
Scaffold(
  body: Stack(
    children: [
      Container(
        height: MediaQuery.of(context).size.height,
        color: Colors.blue.withOpacity(0.5),
      ),
      // Your widgets here
    ],
  ),
);
  1. Use the positioned widget to place your other widgets on top of the container.
Scaffold(
  body: Stack(
    children: [
      Container(
        height: MediaQuery.of(context).size.height,
        color: Colors.blue.withOpacity(0.5),
      ),
      Positioned(
        top: 100,
        left: 50,
        child: Text("Hello World"),
      ),
    ],
  ),
);
  1. Finally, make the positioned widget transparent by giving it a transparent color.
Scaffold(
  body: Stack(
    children: [
      Container(
        height: MediaQuery.of(context).size.height,
        color: Colors.blue.withOpacity(0.5),
      ),
      Positioned(
        top: 100,
        left: 50,
        child: Container(
          color: Colors.transparent,
          child: Text("Hello World"),
        ),
      ),
    ],
  ),
);

By following these steps, you can create a floating widget background in Flutter/Dart.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-22 23:45:47 +0000

Seen: 14 times

Last updated: Jun 23 '23