import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: const NeumorphismPage(),
);
}
}
class NeumorphismPage extends StatefulWidget {
const NeumorphismPage({Key? key}) : super(key: key);
@override
State<NeumorphismPage> createState() => _NeumorphismPageState();
}
class _NeumorphismPageState extends State<NeumorphismPage> {
// Boolean to check whether the
// button is elevated or not.
bool _isElevated = false;
@override
Widget build(BuildContext context) {
return Scaffold(
// Providing background
// color to our Scaffold
backgroundColor: Colors.grey[300],
body: Center(
// Gesture Detector to detect taps
child: GestureDetector(
onTap: () {
setState(() {
_isElevated = !_isElevated;
});
},
child: AnimatedContainer(
child: Image.asset("assets/gfg.png", scale: 3),
// Providing duration parameter
// to create animation
duration: const Duration(milliseconds: 200),
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.grey[300],
shape: BoxShape.circle,
// If widget is not elevated, elevate it.
boxShadow:
_isElevated
?
// Elevation Effect
[
const BoxShadow(
color: Color(0xFFBEBEBE),
// Shadow for bottom right corner
offset: Offset(10, 10),
blurRadius: 30,
spreadRadius: 1,
),
const BoxShadow(
color: Colors.white,
// Shadow for top left corner
offset: Offset(-10, -10),
blurRadius: 30,
spreadRadius: 1,
),
]
: null,
),
),
),
),
);
}
}