Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elevation not working on flutter material

I want to do an app that looks like this Shrine App with that slice on the corner. I can make that slide but my app doesn't have that shadow.

I have my front layer wraped inside a material wideget with elevation like in the example MDC-104.

Here is my code to make that cut

import 'package:flutter/material.dart';

class ShapeLayer extends StatelessWidget {
  final Widget frontLayer;
  final Widget backLayer = Container(
    color: Colors.green,
  );

  ShapeLayer({Key key, this.frontLayer}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        backLayer,
        Material(
          elevation: 60.0,
          shape: BeveledRectangleBorder(
            borderRadius: BorderRadius.only(topLeft: Radius.circular(46.0)),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Expanded(child: frontLayer),
            ],
          ),
        ),
      ],
    );
  }
}

I use it like this:

return Scaffold(
  appBar: appBar,
  body: ShapeLayer(frontLayer: Container(//Some stuff here)

And it looks like this: My App

As you can see it looks flat, with no elevation at all.

How can I fix this?

Thanks!

EDIT: as @SnakeyHips suggests, this is my app with elevation 16.0

elevation 16.0

like image 943
Isaac Avatar asked Nov 14 '18 11:11

Isaac


People also ask

How do you get elevation in Flutter?

Here's are the steps: Step 1: Add the Container widget which you would like to elevate. Step 2: Wrap the Container widget inside of the Material widget. Step 3: Add the elevation parameter (inside Material) and assign the appropriate value.

Can we give elevation to container in Flutter?

Unfortunately there is no elevation property for Container , you need to use other Widget such as Card , but if you really do want to give Container an elevation property, you could take a look at division and watch this tutorial about using that package.

What is elevation in appbar Flutter?

elevation. The z-coordinate at which to place this app bar relative to its parent. This property controls the size of the shadow below the app bar if shadowColor is not null. If surfaceTintColor is not null then it will apply a surface tint overlay to the background color (see Material.


1 Answers

Change your elevation from 60.0 to 16.0 should do it:

import 'package:flutter/material.dart';

class ShapeLayer extends StatelessWidget {
  final Widget frontLayer;
  final Widget backLayer = Container(
    color: Colors.green,
  );

  ShapeLayer({Key key, this.frontLayer}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        backLayer,
        Material(
          elevation: 16.0,
          shape: BeveledRectangleBorder(
            borderRadius: BorderRadius.only(topLeft: Radius.circular(46.0)),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Expanded(child: frontLayer),
            ],
          ),
        ),
      ],
    );
  }
}
like image 81
soupjake Avatar answered Oct 17 '22 11:10

soupjake