A gradient component is provided in FLUTTER, but only if Container is used, as described below:
import 'package:flutter/material.dart';
class JianBianColor extends StatefulWidget {
@override
_JianBianColorState createState() => _JianBianColorState();
}
class _JianBianColorState extends State<JianBianColor> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Gradient setting'),),body: SafeArea(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 20),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.red,
Colors.orange,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
)
),
width: 300.height: 100,
)
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.red,
Colors.orange,
Colors.yellow,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)
),
width: 300.height: 100,
)
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.red,
Colors.orange,
Colors.yellow,
Colors.blue,
],
begin: Alignment.bottomLeft,
end: Alignment.bottomRight,
)
),
width: 300.height: 100,
)
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.red,
Colors.orange,
Colors.yellow,
Colors.green,
Colors.cyan
],
begin: Alignment.topRight,
end: Alignment.bottomLeft,
)
),
width: 300.height: 100,
)
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.red,
Colors.orange,
Colors.yellow,
Colors.green,
Colors.cyan,
Colors.blue,
Colors.purple
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
)
),
width: 300.height: 100(() (() [() [() [() [() [() [() }}Copy the code
It is worth mentioning that the color property should not be used if you use decoration to set gradients.