How To Implementing Shadow Overlay In Flutter ?

Spread the love
How To Implementing Shadow Overlay In Flutter
How To Implementing Shadow Overlay In Flutter

Introduction

The shadow_overlay package provides a way to add a shadow overlay effect to your widgets in Flutter, enhancing their visual appearance.

Content

1.Add the shadow_overlay dependency:

Open your pubspec.yaml file and add the shadow_overlay dependency.


dependencies:
  hidable: ^latest_version

Run flutter pub get to install the package.

 

2.Import the package:

Import the shadow_overlay package in your Dart file.


import 'package:shadow_overlay/shadow_overlay.dart';

 

3.Create a Shadow Overlay Widget:

Wrap the widget that you want to apply the shadow overlay effect to with the ShadowOverlay widget.


ShadowOverlay(
  child: YourWidget(),
  overlayColor: Colors.black.withOpacity(0.5), // Set the color and opacity of the overlay
  shadowColor: Colors.grey, // Set the color of the shadow
  shadowBlurRadius: 10.0, // Set the blur radius of the shadow
  shadowSpreadRadius: 2.0, // Set the spread radius of the shadow
),

 

4.Run the app:

Run your Flutter app to see the shadow overlay effect applied to your widget.

 

Sample Code


import 'package:flutter/material.dart';

import 'package:shadow_overlay/shadow_overlay.dart';

void main(List<String> args) {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      // you can change theme to make overlay accord.
      themeMode: ThemeMode.light,
      darkTheme: ThemeData.dark(),
      theme: ThemeData.light(),
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final _isDark = Theme.of(context).brightness == Brightness.dark;
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.cyan,
        centerTitle: true,
        title: Text("Shadow Overlay"),
      ),
      backgroundColor: _isDark ? Colors.black : Colors.white,
      body: Center(
        child: ShadowOverlay(
          shadowHeight: 150,
          shadowWidth: 400,
          shadowColor: _isDark ? const Color.fromARGB(255, 34, 31, 31) : Colors.white,
          child: Image.network(
            'https://images.unsplash.com/photo-1492144534655-ae79c964c9d7?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8Y2Fyc3xlbnwwfHwwfHx8MA%3D%3D',
            fit: BoxFit.cover,
            height: 400,
            width: 400,
          ),
        ),
      ),
    );
  }
}

Output

How To Implementing Shadow Overlay In Flutter
How To Implementing Shadow Overlay In Flutter

Conclusion

By following these steps, you can easily implement a shadow overlay effect in Flutter using the shadow_overlay package. This can be useful for adding depth and visual interest to your app’s UI elements.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *