How to add opacity a container in flutter? Fade a container?

This Article is posted by seven.srikanth at 11/24/2022 1:09:33 AM



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

Tags: fade widget;








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com