flutter corner radius with transparent background

后端 未结 11 1005
鱼传尺愫
鱼传尺愫 2021-01-30 15:28

Below is my code which I expect to render a round-corner container with a transparent background.

return new Container(
                //padding: const EdgeIn         


        
相关标签:
11条回答
  • 2021-01-30 16:14

    If both containers are siblings and the bottom container has rounded corners and the top container is dynamic then you will have to use the stack widget

    Stack(
     children: [
       /*your_widget_1*/,
      /*your_widget_2*/,
     ],
    );
    
    0 讨论(0)
  • 2021-01-30 16:17

    It's an old question. But for those who come across this question...

    The white background behind the rounded corners is not actually the container. That is the canvas color of the app.

    TO FIX: Change the canvas color of your app to Colors.transparent

    Example:

    return new MaterialApp(
      title: 'My App',
      theme: new ThemeData(
        primarySwatch: Colors.green,
        canvasColor: Colors.transparent, //----Change to this------------
        accentColor: Colors.blue,
      ),
      home: new HomeScreen(),
    );
    
    0 讨论(0)
  • 2021-01-30 16:19

    If you want to round corners with transparent background, the best approach is using ClipRRect.

    return ClipRRect(
      borderRadius: BorderRadius.circular(40.0),
      child: Container(
        height: 800.0,
        width: double.infinity,
        color: Colors.blue,
        child: Center(
          child: new Text("Hi modal sheet"),
        ),
      ),
    );
    
    0 讨论(0)
  • 2021-01-30 16:23

    Three related packages for covering this issue with many advanced options are:

    • sliding_up_panel
    • modal_bottom_sheet
    • sliding_panel
    0 讨论(0)
  • 2021-01-30 16:24
    class MyApp2 extends StatelessWidget {
    
      @override
      Widget build(BuildContext context) { 
        return MaterialApp( 
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            appBarTheme: AppBarTheme(
              elevation: 0,
              color: Colors.blueAccent,
            )
          ),
          title: 'Welcome to flutter ',
          home: HomePage()
        );
      }
    }
    
    class HomePage extends StatefulWidget {
      @override
      _HomePageState createState() => _HomePageState();
    }
    
    class _HomePageState extends State<HomePage> {
    
      int number = 0;
      void _increment(){
       setState(() {
          number ++;
       });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            backgroundColor: Colors.blueAccent,
            appBar: AppBar(
              title: Text('MyApp2'), 
              leading: Icon(Icons.menu),
              // backgroundColor: Colors.blueAccent,
    
              ),
            body: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(200.0),
                  topRight: Radius.circular(200)
                ), 
                color: Colors.white,
              ),
            )
          );
      }
    }
    
    0 讨论(0)
提交回复
热议问题