Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to create a widget class that is transparent?

Tags:

flutter

dart

I would like to create a new widget class with a container size of 250x500 with the rest of the class/widget 0.5 opacity - allowing the prior widget - we launched from - to be partially visible.

Is this possible ? if so how ?

-Thanks

Below is the Stateful class I am calling

class ShowMyTitles extends StatefulWidget {
  @override
  _ShowMyTitlesState createState() => _ShowMyTitlesState();
}

class _ShowMyTitlesState extends State<ShowMyTitles> {


  List<Map<String, bool>> myListOfMapTitles;
  Map<String, bool> valuesHeaders;
  int trueCount = 0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    SettingsForMap SFM = new SettingsForMap();
    myListOfMapTitles = SFM.myListOfMapTitles;
    valuesHeaders = SFM.valuesHeaders;
  }


  @override
  Widget build(BuildContext context) {

    List myTitles = [];

    return new WillPopScope(
      onWillPop: (){
        myListOfMapTitles.forEach((valuesAll) {
          valuesAll.forEach((s,b){
            if(b == true) {
              myTitles.add(s);
              print('My Selecteed titles are = ' + s.toString());
            }
          });

        });
        Navigator.pop(context, myTitles);

      },
      child: new Container(
        child: new GestureDetector(
          onTap: (){
            myListOfMapTitles.forEach((valuesAll) {
              valuesAll.forEach((s,b){
                if(b == true) {
                  myTitles.add(s);
                  print('My Selecteed titles are = ' + s.toString());
                }
              });

            });
            Navigator.pop(context, myTitles);
          },
          child: _titlesDialog(context, 'Select 2 Titles (Max)'),
        ),
      ),
    );
  }
like image 659
AhabLives Avatar asked Dec 18 '22 22:12

AhabLives


2 Answers

There is an Opacity widget. Wrap the widget you want to be transparent within it.

Opacity(child:MyTransparentWidget(),opacity:0.45)

like image 110
Shady Aziza Avatar answered Feb 12 '23 08:02

Shady Aziza


You can use Stack widget for that.

Surround the widget which you want to change the opacity and the container with Stack widget.

Then wrap the widget which you want to change the opacity with Opacity widget and mention required opacity.

Make sure you put the container after the widget which you want to change the opacity then only it will sit above the transparent widget

like image 25
Vinoth Kumar Avatar answered Feb 12 '23 07:02

Vinoth Kumar