How to Create Beautiful Neumorphic Designs with Clay Containers in Flutter

Sep 3, 2021 | Programming

Welcome to the fascinating world of neumorphism! If you’re looking to elevate your Flutter project with stunning, modern designs, the neumorphic style is a fantastic choice. In this guide, we will explore how to easily create and customize beautiful clay containers that serve as the backbone of your unique neumorphic designs.

Installation

Getting started is simple! Follow these steps to add clay_containers to your Flutter project:

  • Open your pubspec.yaml file.
  • Add clay_containers as a dependency.
  • Save the file to install the package.

Since it’s a straightforward Dart plugin, you won’t need to worry about extra configurations for iOS or Android!

Creating Simple Clay Containers

To get the best results with your ClayContainer, it’s recommended to set the background color of its surrounding widget to match the ClayContainer’s color. Let’s consider this color as the base, which we will reuse throughout.

Here’s a simple example:

import 'package:clay_containers/clay_containers.dart';

class MyExampleScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Color baseColor = Color(0xFFF2F2F2); // Define your base color
    return Container(
      color: baseColor,
      child: Center(
        child: ClayContainer(
          color: baseColor,
          height: 200,
          width: 200,
        ),
      ),
    );
  }
}

In this analogy, think of the ClayContainer as a piece of clay that you can mold into anything you wish. It’s all about setting a solid foundation (the base color) upon which you can add your unique designs!

Adding Text to Clay Containers

The ClayContainer can also hold children widgets, making it tremendously flexible. Here’s how to add a ClayText child with some additional padding:

ClayContainer(
  color: baseColor,
  child: Padding(
    padding: EdgeInsets.all(20),
    child: ClayText("Seize the Clay!", emboss: true, size: 40),
  ),
);

With this setup, you’re not just creating a container; you’re crafting a complete, interactive experience!

Enhancing with Rounded Corners

Who wants to be square? You can add a charming touch with rounded corners using the borderRadius property:

ClayContainer(
  color: baseColor,
  height: 150,
  width: 150,
  borderRadius: 50, // This creates a rounded effect
);

In this way, your containers won’t just look good; they’ll have personality!

Embossed Effects

Neumorphic design is all about depth. You can achieve this with the emboss property:

ClayContainer(
  emboss: true,
  color: baseColor,
  height: 150,
  width: 150,
  borderRadius: 50,
);

The embossed effect creates the illusion of shadows and light, making your design pop off the screen!

Customizing Spread and Depth

If the default look of the neumorphic effect doesn’t suit your style, you can customize the spread and depth:

ClayContainer(
  color: baseColor,
  height: 150,
  width: 150,
  borderRadius: 75,
  depth: 40, // Set the depth
  spread: 40, // Set how far it spreads
);

Feel free to play around and express your creativity! The only limits are your imagination.

Concave and Convex Containers

Add even more flair by creating concave or convex shapes:

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children: [
    ClayContainer(
      color: baseColor,
      height: 150,
      width: 150,
      borderRadius: 75,
      curveType: CurveType.concave, // Make it concave
    ),
    SizedBox(width: 50),
    ClayContainer(
      color: baseColor,
      height: 150,
      width: 150,
      borderRadius: 75,
      curveType: CurveType.convex, // Make it convex
    ),
  ],
);

This variety adds complexity and visual interest to your work!

Animating Clay Containers

If you want your design to dance, use ClayAnimatedContainer. You can animate properties the same way you would with a standard AnimatedContainer:

ClayAnimatedContainer(
  duration: Duration(seconds: 1), // Set the animation duration
  height: 240,
  width: 240,
  child: ClayContainer(
    borderRadius: 10,
  ),
);

Your designs are not only static; they can be dynamic and engaging!

Theming Your Clay Containers

To unify the look across multiple containers, use ClayTheme. Here’s how to set it up:

ClayTheme(
  themeData: const ClayThemeData(
    height: 10,
    width: 20,
    borderRadius: 360,
    depth: 12,
  ),
  child: (...), // Your widget tree
);

Now all child containers will inherit this theme, ensuring consistency in your designs!

Troubleshooting

If you encounter issues, here are some common solutions:

  • Verify that clay_containers is added correctly to your pubspec.yaml file.
  • Ensure that Flutter is set up correctly on your machine.
  • If your containers don’t display correctly, check the colors and sizes you’ve set. They should align with your design.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Now that you’re armed with all this knowledge, get out there and start creating stunning neumorphic designs!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox