Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created February 16, 2020 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlid/e4d66e9ac19a4817358606eb43da6866 to your computer and use it in GitHub Desktop.
Save ryanlid/e4d66e9ac19a4817358606eb43da6866 to your computer and use it in GitHub Desktop.
LinearGradient 线性渐变效果
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: "LinearGradient线性渐变效果",
home: LayoutDemo(),
),
);
}
class LayoutDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("LinearGradient线性渐变效果"),
),
body: Center(
child: DecoratedBox(
decoration: BoxDecoration(
// 线性渐变
gradient: LinearGradient(
// 起始偏移量
begin: FractionalOffset(0.5, 0.0),
// 结束偏移量
end: FractionalOffset(1.0, 1.0),
// 渐变颜色数据集
colors: <Color>[
Colors.red,
Colors.green,
Colors.blue,
Colors.grey,
],
),
),
child: Container(
width: 280.0,
height: 280.0,
child: Center(
child: Text(
"LinearGradient线性渐变效果",
style: TextStyle(
color: Colors.black,
fontSize: 28.0,
),
),
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment