Let's see how to add Opacity to a container in flutter.
Here is the expected outcome of this example.
You can achieve this using the Opacity widget.
Here is the complete code from main.dart file.
import 'package:flutter/material.dart';
void main(List<String> args) {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@
override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: MyLayoutWidget(),
),
);
}
}
class MyLayoutWidget extends StatelessWidget {
const MyLayoutWidget({
super.key,
});
@
override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Opacity(
opacity: 0.5,
child: Container(
height: 200,
width: 200,
color: Colors.blue,
child: const Center(child: Text("With Opacity")),
),
),
Container(
height: 200,
width: 200,
color: Colors.blue,
child: const Center(child: Text("Without Opacity")),
)
],
),
);
}
}
Thanks,Srikanth