Opacity (Container) with Slider Simple Example

 import "package:flutter/material.dart";


void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Opacity Example",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: const OpacityExample(),
);
}
}

class OpacityExample extends StatefulWidget {
const OpacityExample({super.key});

@override
State<OpacityExample> createState() {
return OpacityExampleState();
}
}

class OpacityExampleState extends State<OpacityExample> {
double opacity = 0.4;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Opacity Example"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 200.0,
height: 200.0,
color: Colors.brown.withOpacity(opacity),
),
const SizedBox(height: 50.0),
Slider(
value: opacity,
onChanged: (value) {
print(value);
opacity = value;
setState(() {});
},
),
],
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter