How do I draw a vector shape in Flutter?












2















We are trying to build a custom shape vector in Flutter that can be changed at runtime.



For example, we need a pizza shape vector widget that we can change the slice color base on a variable value.



We tried to use the canvas and painter in Flutter but they don't have a clear and good doc.



We tried SVG too but unfortunately Flutter doesn't support SVG tag and SVG view too.










share|improve this question





























    2















    We are trying to build a custom shape vector in Flutter that can be changed at runtime.



    For example, we need a pizza shape vector widget that we can change the slice color base on a variable value.



    We tried to use the canvas and painter in Flutter but they don't have a clear and good doc.



    We tried SVG too but unfortunately Flutter doesn't support SVG tag and SVG view too.










    share|improve this question



























      2












      2








      2








      We are trying to build a custom shape vector in Flutter that can be changed at runtime.



      For example, we need a pizza shape vector widget that we can change the slice color base on a variable value.



      We tried to use the canvas and painter in Flutter but they don't have a clear and good doc.



      We tried SVG too but unfortunately Flutter doesn't support SVG tag and SVG view too.










      share|improve this question
















      We are trying to build a custom shape vector in Flutter that can be changed at runtime.



      For example, we need a pizza shape vector widget that we can change the slice color base on a variable value.



      We tried to use the canvas and painter in Flutter but they don't have a clear and good doc.



      We tried SVG too but unfortunately Flutter doesn't support SVG tag and SVG view too.







      android vector flutter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 10:11







      javad bat

















      asked Apr 17 '18 at 14:56









      javad batjavad bat

      444620




      444620
























          1 Answer
          1






          active

          oldest

          votes


















          3














          You can create a widget that extends CustomPainter




          class Sky extends CustomPainter {
          @override
          void paint(Canvas canvas, Size size) {
          var rect = Offset.zero & size;
          var gradient = new RadialGradient(
          center: const Alignment(0.7, -0.6),
          radius: 0.2,
          colors: [const Color(0xFFFFFF00), const Color(0xFF0099FF)],
          stops: [0.4, 1.0],
          );
          canvas.drawRect(
          rect,
          new Paint()..shader = gradient.createShader(rect),
          );
          }

          @override
          SemanticsBuilderCallback get semanticsBuilder {
          return (Size size) {
          // Annotate a rectangle containing the picture of the sun
          // with the label "Sun". When text to speech feature is enabled on the
          // device, a user will be able to locate the sun on this picture by
          // touch.
          var rect = Offset.zero & size;
          var width = size.shortestSide * 0.4;
          rect = const Alignment(0.8, -0.9).inscribe(new Size(width, width), rect);
          return [
          new CustomPainterSemantics(
          rect: rect,
          properties: new SemanticsProperties(
          label: 'Sun',
          textDirection: TextDirection.ltr,
          ),
          ),
          ];
          };
          }

          // Since this Sky painter has no fields, it always paints
          // the same thing and semantics information is the same.
          // Therefore we return false here. If we had fields (set
          // from the constructor) then we would return true if any
          // of them differed from the same fields on the oldDelegate.
          @override
          bool shouldRepaint(Sky oldDelegate) => false;
          @override
          bool shouldRebuildSemantics(Sky oldDelegate) => false;
          }



          See also





          • https://pub.dartlang.org/packages/flutter_svg (limited SVG support for Flutter)

          • https://github.com/flutter/flutter/tree/master/dev/tools/vitool


          • https://github.com/simolus3/fluttie (not sure this is working already)






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49881407%2fhow-do-i-draw-a-vector-shape-in-flutter%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            You can create a widget that extends CustomPainter




            class Sky extends CustomPainter {
            @override
            void paint(Canvas canvas, Size size) {
            var rect = Offset.zero & size;
            var gradient = new RadialGradient(
            center: const Alignment(0.7, -0.6),
            radius: 0.2,
            colors: [const Color(0xFFFFFF00), const Color(0xFF0099FF)],
            stops: [0.4, 1.0],
            );
            canvas.drawRect(
            rect,
            new Paint()..shader = gradient.createShader(rect),
            );
            }

            @override
            SemanticsBuilderCallback get semanticsBuilder {
            return (Size size) {
            // Annotate a rectangle containing the picture of the sun
            // with the label "Sun". When text to speech feature is enabled on the
            // device, a user will be able to locate the sun on this picture by
            // touch.
            var rect = Offset.zero & size;
            var width = size.shortestSide * 0.4;
            rect = const Alignment(0.8, -0.9).inscribe(new Size(width, width), rect);
            return [
            new CustomPainterSemantics(
            rect: rect,
            properties: new SemanticsProperties(
            label: 'Sun',
            textDirection: TextDirection.ltr,
            ),
            ),
            ];
            };
            }

            // Since this Sky painter has no fields, it always paints
            // the same thing and semantics information is the same.
            // Therefore we return false here. If we had fields (set
            // from the constructor) then we would return true if any
            // of them differed from the same fields on the oldDelegate.
            @override
            bool shouldRepaint(Sky oldDelegate) => false;
            @override
            bool shouldRebuildSemantics(Sky oldDelegate) => false;
            }



            See also





            • https://pub.dartlang.org/packages/flutter_svg (limited SVG support for Flutter)

            • https://github.com/flutter/flutter/tree/master/dev/tools/vitool


            • https://github.com/simolus3/fluttie (not sure this is working already)






            share|improve this answer






























              3














              You can create a widget that extends CustomPainter




              class Sky extends CustomPainter {
              @override
              void paint(Canvas canvas, Size size) {
              var rect = Offset.zero & size;
              var gradient = new RadialGradient(
              center: const Alignment(0.7, -0.6),
              radius: 0.2,
              colors: [const Color(0xFFFFFF00), const Color(0xFF0099FF)],
              stops: [0.4, 1.0],
              );
              canvas.drawRect(
              rect,
              new Paint()..shader = gradient.createShader(rect),
              );
              }

              @override
              SemanticsBuilderCallback get semanticsBuilder {
              return (Size size) {
              // Annotate a rectangle containing the picture of the sun
              // with the label "Sun". When text to speech feature is enabled on the
              // device, a user will be able to locate the sun on this picture by
              // touch.
              var rect = Offset.zero & size;
              var width = size.shortestSide * 0.4;
              rect = const Alignment(0.8, -0.9).inscribe(new Size(width, width), rect);
              return [
              new CustomPainterSemantics(
              rect: rect,
              properties: new SemanticsProperties(
              label: 'Sun',
              textDirection: TextDirection.ltr,
              ),
              ),
              ];
              };
              }

              // Since this Sky painter has no fields, it always paints
              // the same thing and semantics information is the same.
              // Therefore we return false here. If we had fields (set
              // from the constructor) then we would return true if any
              // of them differed from the same fields on the oldDelegate.
              @override
              bool shouldRepaint(Sky oldDelegate) => false;
              @override
              bool shouldRebuildSemantics(Sky oldDelegate) => false;
              }



              See also





              • https://pub.dartlang.org/packages/flutter_svg (limited SVG support for Flutter)

              • https://github.com/flutter/flutter/tree/master/dev/tools/vitool


              • https://github.com/simolus3/fluttie (not sure this is working already)






              share|improve this answer




























                3












                3








                3







                You can create a widget that extends CustomPainter




                class Sky extends CustomPainter {
                @override
                void paint(Canvas canvas, Size size) {
                var rect = Offset.zero & size;
                var gradient = new RadialGradient(
                center: const Alignment(0.7, -0.6),
                radius: 0.2,
                colors: [const Color(0xFFFFFF00), const Color(0xFF0099FF)],
                stops: [0.4, 1.0],
                );
                canvas.drawRect(
                rect,
                new Paint()..shader = gradient.createShader(rect),
                );
                }

                @override
                SemanticsBuilderCallback get semanticsBuilder {
                return (Size size) {
                // Annotate a rectangle containing the picture of the sun
                // with the label "Sun". When text to speech feature is enabled on the
                // device, a user will be able to locate the sun on this picture by
                // touch.
                var rect = Offset.zero & size;
                var width = size.shortestSide * 0.4;
                rect = const Alignment(0.8, -0.9).inscribe(new Size(width, width), rect);
                return [
                new CustomPainterSemantics(
                rect: rect,
                properties: new SemanticsProperties(
                label: 'Sun',
                textDirection: TextDirection.ltr,
                ),
                ),
                ];
                };
                }

                // Since this Sky painter has no fields, it always paints
                // the same thing and semantics information is the same.
                // Therefore we return false here. If we had fields (set
                // from the constructor) then we would return true if any
                // of them differed from the same fields on the oldDelegate.
                @override
                bool shouldRepaint(Sky oldDelegate) => false;
                @override
                bool shouldRebuildSemantics(Sky oldDelegate) => false;
                }



                See also





                • https://pub.dartlang.org/packages/flutter_svg (limited SVG support for Flutter)

                • https://github.com/flutter/flutter/tree/master/dev/tools/vitool


                • https://github.com/simolus3/fluttie (not sure this is working already)






                share|improve this answer















                You can create a widget that extends CustomPainter




                class Sky extends CustomPainter {
                @override
                void paint(Canvas canvas, Size size) {
                var rect = Offset.zero & size;
                var gradient = new RadialGradient(
                center: const Alignment(0.7, -0.6),
                radius: 0.2,
                colors: [const Color(0xFFFFFF00), const Color(0xFF0099FF)],
                stops: [0.4, 1.0],
                );
                canvas.drawRect(
                rect,
                new Paint()..shader = gradient.createShader(rect),
                );
                }

                @override
                SemanticsBuilderCallback get semanticsBuilder {
                return (Size size) {
                // Annotate a rectangle containing the picture of the sun
                // with the label "Sun". When text to speech feature is enabled on the
                // device, a user will be able to locate the sun on this picture by
                // touch.
                var rect = Offset.zero & size;
                var width = size.shortestSide * 0.4;
                rect = const Alignment(0.8, -0.9).inscribe(new Size(width, width), rect);
                return [
                new CustomPainterSemantics(
                rect: rect,
                properties: new SemanticsProperties(
                label: 'Sun',
                textDirection: TextDirection.ltr,
                ),
                ),
                ];
                };
                }

                // Since this Sky painter has no fields, it always paints
                // the same thing and semantics information is the same.
                // Therefore we return false here. If we had fields (set
                // from the constructor) then we would return true if any
                // of them differed from the same fields on the oldDelegate.
                @override
                bool shouldRepaint(Sky oldDelegate) => false;
                @override
                bool shouldRebuildSemantics(Sky oldDelegate) => false;
                }



                See also





                • https://pub.dartlang.org/packages/flutter_svg (limited SVG support for Flutter)

                • https://github.com/flutter/flutter/tree/master/dev/tools/vitool


                • https://github.com/simolus3/fluttie (not sure this is working already)







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 3 at 10:12

























                answered Apr 17 '18 at 15:36









                Günter ZöchbauerGünter Zöchbauer

                332k701006941




                332k701006941
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49881407%2fhow-do-i-draw-a-vector-shape-in-flutter%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    generate and download xml file after input submit (php and mysql) - JPK

                    Angular Downloading a file using contenturl with Basic Authentication

                    Can't read property showImagePicker of undefined in react native iOS