Skip to content

Instantly share code, notes, and snippets.

@JanStorm
Created April 29, 2020 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JanStorm/fb958b595ab1cf82b9a5afabbb36cca0 to your computer and use it in GitHub Desktop.
Save JanStorm/fb958b595ab1cf82b9a5afabbb36cca0 to your computer and use it in GitHub Desktop.
Flutter Image ambient backlight
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
import 'dart:ui';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Image ambient backlight"),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ImageColoredShadow(),
Center(child: Text("This is a caption"))
])));
}
}
class ImageColoredShadow extends StatelessWidget {
@override
Widget build(BuildContext context) {
double _size = 200.0;
double blurRadius = 20.0;
double blurSigma = 7.0;
String imageUrl = 'https://mp-prod-de-medialib.s3-eu-central-1.amazonaws.com/motivwelt/stockimage/buntes-laub/overview/buntes-laub-l.jpg';
return Stack(children: [
Center(
child: ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: new Container(
width: _size + blurRadius,
height: _size + blurRadius,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.cover,
image: new NetworkImage(imageUrl))),
)))),
Positioned.fill(
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: blurSigma, sigmaY: blurSigma),
child: Container(color: Colors.black.withOpacity(0)))),
Positioned.fill(
child: Center(
child: new Container(
width: _size,
height: _size,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.cover,
image: new NetworkImage(imageUrl)))),
),
)
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment