flutter 渐变Gradient


import "package:flutter/material.dart";
import 'package:kdbflutter/common/GDimens.dart';

class GradientUtil {
  static LinearGradient _getLinearGradient(Color left, Color right,
          {begin = AlignmentDirectional.centerStart,
          end = AlignmentDirectional.centerEnd,
          opacity = 1.0}) =>
      LinearGradient(
        colors: [
          left.withOpacity(opacity),
          right.withOpacity(opacity),
        ],
        begin: begin,
        end: end,
      );

  static LinearGradient yellowGreen(
          {begin = AlignmentDirectional.centerStart,
          end = AlignmentDirectional.centerEnd,
          opacity = 1.0}) =>
      _getLinearGradient(GDimens.YELLOW, GDimens.GREEN,
          begin: begin, end: end, opacity: opacity);

  static LinearGradient red(
          {begin = AlignmentDirectional.centerStart,
          end = AlignmentDirectional.centerEnd,
          opacity = 1.0}) =>
      _getLinearGradient(GDimens.RED_LIGHT, GDimens.RED,
          begin: begin, end: end, opacity: opacity);

  static LinearGradient yellowBlue(
          {begin = AlignmentDirectional.centerStart,
          end = AlignmentDirectional.centerEnd,
          opacity = 1.0}) =>
      _getLinearGradient(GDimens.YELLOW, GDimens.BLUE,
          begin: begin, end: end, opacity: opacity);

  static LinearGradient blue(
          {begin = AlignmentDirectional.centerStart,
          end = AlignmentDirectional.centerEnd,
          opacity = 1.0}) =>
      _getLinearGradient(GDimens.BLUE_LIGHT, GDimens.BLUE_DEEP,
          begin: begin, end: end, opacity: opacity);

  static LinearGradient greenRed(
          {begin = AlignmentDirectional.centerStart,
          end = AlignmentDirectional.centerEnd,
          opacity = 1.0}) =>
      _getLinearGradient(GDimens.GREEN, GDimens.RED, begin: begin, end: end, opacity: opacity);

  static LinearGradient greenPurple(
          {begin = AlignmentDirectional.centerStart,
          end = AlignmentDirectional.centerEnd,
          opacity = 1.0}) =>
      _getLinearGradient(GDimens.GREEN, GDimens.PURPLE,
          begin: begin, end: end, opacity: opacity);
}
//使用
//gradient: GradientUtil.red(),

 

你可能感兴趣的:(flutter)