11import { BoxDecoration } from "@flutter-builder/flutter" ;
2- import { Color } from "@reflect-ui/core" ;
2+ import { Color , Gradient , GradientType } from "@reflect-ui/core" ;
33import { Background } from "@reflect-ui/core/lib/background" ;
44import * as dartui from "../dart-ui" ;
5+ import { linearGradient } from "./painting-linear-gradient" ;
6+ import { radialGradient } from "./painting-radial-gradient" ;
57
68function fromColor ( color : Color ) : BoxDecoration {
79 return new BoxDecoration ( {
@@ -19,7 +21,7 @@ function fromBackground(b: Background): BoxDecoration {
1921 } else {
2022 switch ( b . type ) {
2123 case "gradient" : {
22- console . error ( "gradient bg not ready" ) ;
24+ return fromGradient ( b as Gradient ) ;
2325 break ;
2426 }
2527 case "graphics" : {
@@ -33,8 +35,32 @@ function fromBackground(b: Background): BoxDecoration {
3335 }
3436}
3537
36- function fromGradient ( ) : BoxDecoration {
37- throw "not ready." ;
38+ function fromGradient ( g : Gradient ) : BoxDecoration {
39+ switch ( g ?. _type ) {
40+ case GradientType . LINEAR : {
41+ return new BoxDecoration ( {
42+ gradient : linearGradient ( g ) ,
43+ } ) ;
44+ }
45+ case GradientType . RADIAL : {
46+ return new BoxDecoration ( {
47+ gradient : radialGradient ( g ) ,
48+ } ) ;
49+ }
50+
51+ // It is only used to make it safer in case of an emergency.
52+ case undefined : {
53+ return ;
54+ }
55+ default : {
56+ // TODO: add;
57+ // GRADIENT_ANGULAR;
58+ // GRADIENT_DIAMOND;
59+ throw new Error (
60+ `Gradient type of "${ g } " is not yet supported on flutter platform.`
61+ ) ;
62+ }
63+ }
3864}
3965
4066function fromImage ( ) : BoxDecoration {
0 commit comments