flutter - 如何在颤动的任何小部件周围制作渐变阴影?
解决方案
通过使用这个,我实现了你想要的。
import 'package:flutter/material.dart';
import 'gradient_decoration.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget _buildBody() {
return Center(
child: Container(
width: 300,
height: 80,
decoration: GradientShadowBoxDecoration(
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
offset: Offset(0.0, 0.0),
blurRadius: 25,
),
],
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Colors.blue,
Colors.purple,
],
)),
child: Center(
child: Text(
'Login',
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
);
}
}
推荐阅读
- firebase - Firebase 服务帐户生成身份验证令牌以供客户端与 Google Apps 脚本一起使用
- angular - angular 6 选择框添加第一个值作为默认值
- css - React JS 中的悬挂缩进
- javascript - 如何仅在 getCurrentLocation 之后才能使反向地理编码起作用?
- c - 函数中整数和寄存器常量字符的解释
- asp.net-mvc - 控制器未添加到 asp net core 和 simplcommerce 项目中
- laravel - 编辑和创建刀片后,我的索引突然出现“试图获取非对象的属性”
- android - Android Studio - 布局编辑器全部模糊
- salesforce - 如何在 Salesforce 中创建自定义应用内通知?
- c - 无法在c中使用堆的基地址