Skip to content

Instantly share code, notes, and snippets.

@blaugold
Created December 30, 2021 22:27
Show Gist options
  • Save blaugold/e0eaa2c1ed136d984c1ddaa24edbe755 to your computer and use it in GitHub Desktop.
Save blaugold/e0eaa2c1ed136d984c1ddaa24edbe755 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'dart:ui';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var glassCenter = const Offset(150, 150);
@override
Widget build(BuildContext context) {
const glassSize = Size(200, 200);
const glassZoom = 1.25;
final glassOffset = glassCenter - glassSize.center(Offset.zero);
final centerCorrection = (glassCenter * (glassZoom - 1.0)) * -1.0;
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: MouseRegion(
onHover: (details) {
setState(() {
glassCenter = details.localPosition;
});
},
child: LayoutBuilder(builder: (context, constraints) {
final imageFilterMatrix = Matrix4.translationValues(
centerCorrection.dx,
centerCorrection.dy,
0,
) *
Matrix4.identity().scaled(glassZoom);
final imageFilter = ImageFilter.matrix(imageFilterMatrix.storage);
return Stack(children: [
Center(
child: Container(
width: 200,
height: 200,
decoration: const BoxDecoration(
shape: BoxShape.rectangle,
color: Colors.red,
),
),
),
Positioned(
top: glassOffset.dy,
left: glassOffset.dx,
width: glassSize.width,
height: glassSize.height,
child: ClipOval(
child: BackdropFilter(
filter: imageFilter,
child: const ColoredBox(
color: Colors.transparent,
),
),
),
)
]);
}),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment