diff --git a/.pubignore b/.pubignore
new file mode 100644
index 0000000..ac8824e
--- /dev/null
+++ b/.pubignore
@@ -0,0 +1,11 @@
+# Files to exclude from pub.dev publishing
+
+SDUI_Flutter_Integration_Guide.txt
+docs/
+.github/
+.hooks/
+.idea/
+\*.iml
+build/
+.dart_tool/
+bin/
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 29a813e..db72851 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,9 +4,12 @@
### Added
-- Basic framework for Server-Driven UI implementation
-- Support for rendering UI from server-provided definitions
-- gRPC integration with Protocol Buffers
-- Core widget support (Text, Column, Row, Container, etc.)
-- Example application demonstrating gRPC usage
-- Setup scripts for Protocol Buffer compilation
+- Server-Driven UI framework for Flutter
+- JSON and gRPC support for dynamic UI rendering
+- Protocol Buffers integration for type-safe communication
+- Core widget support: Text, Column, Row, Container, Scaffold, Image, Icon, SizedBox, Spacer
+- SduiGrpcClient for server communication
+- SduiGrpcRenderer widget for rendering server-driven UI
+- Comprehensive documentation and examples
+- Flutter-to-SDUI conversion utilities
+- Error handling and loading states
diff --git a/LICENSE b/LICENSE
index f288702..514c0e3 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,190 +1,79 @@
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
+MIT License
+
+Copyright (c) 2025 GDSC-VIT and Contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
+control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
+which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
- The Corresponding Source need not include anything that users
+The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
- The Corresponding Source for a work in source code form is that
+The Corresponding Source for a work in source code form is that
same work.
- 2. Basic Permissions.
+2. Basic Permissions.
- All rights granted under this License are granted for the term of
+All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
+content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
- You may make, run and propagate covered works that you do not
+You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
+in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
+not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
+Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+3. Protecting Users' Legal Rights From Anti-Circumvention Law.
- No covered work shall be deemed part of an effective technological
+No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
- When you convey a covered work, you waive any legal power to forbid
+When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
@@ -192,9 +81,9 @@ modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
- 4. Conveying Verbatim Copies.
+4. Conveying Verbatim Copies.
- You may convey verbatim copies of the Program's source code as you
+You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
@@ -202,12 +91,12 @@ non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
- You may charge any price or no price for each copy that you convey,
+You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
- 5. Conveying Modified Source Versions.
+5. Conveying Modified Source Versions.
- You may convey a work based on the Program, or the modifications to
+You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
@@ -232,19 +121,19 @@ terms of section 4, provided that you also meet all of these conditions:
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
- A compilation of a covered work with other separate and independent
+A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
+beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
- 6. Conveying Non-Source Forms.
+6. Conveying Non-Source Forms.
- You may convey a covered work in object code form under the terms
+You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
@@ -290,75 +179,75 @@ in one of these ways:
Source of the work are being offered to the general public at no
charge under subsection 6d.
- A separable portion of the object code, whose source code is excluded
+A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
- A "User Product" is either (1) a "consumer product", which means any
+A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
+actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
- "Installation Information" for a User Product means any methods,
+"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
+a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
- If you convey an object code work under this section in, or with, or
+If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
+by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
- The requirement to provide Installation Information does not include a
+The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
+the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
- Corresponding Source conveyed, and Installation Information provided,
+Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
- 7. Additional Terms.
+7. Additional Terms.
- "Additional permissions" are terms that supplement the terms of this
+"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
+that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
- When you convey a copy of a covered work, you may at your option
+When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
- Notwithstanding any other provision of this License, for material you
+Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
@@ -385,74 +274,74 @@ that material) supplement the terms of this License with terms:
any liability that these contractual assumptions directly impose on
those licensors and authors.
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
+All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
+restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
- If you add terms to a covered work in accord with this section, you
+If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
- Additional terms, permissive or non-permissive, may be stated in the
+Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
- 8. Termination.
+8. Termination.
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
+You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
- However, if you cease all violation of this License, then your
+However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
- Moreover, your license from a particular copyright holder is
+Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
- Termination of your rights under this section does not terminate the
+Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
+this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
- 9. Acceptance Not Required for Having Copies.
+9. Acceptance Not Required for Having Copies.
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
+You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
+to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
- 10. Automatic Licensing of Downstream Recipients.
+10. Automatic Licensing of Downstream Recipients.
- Each time you convey a covered work, the recipient automatically
+Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
+propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
- An "entity transaction" is a transaction transferring control of an
+An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
+organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
@@ -460,43 +349,43 @@ give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
+You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
- 11. Patents.
+11. Patents.
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
+A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
- A contributor's "essential patent claims" are all patent claims
+A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
+consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
- Each contributor grants you a non-exclusive, worldwide, royalty-free
+Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
- In the following three paragraphs, a "patent license" is any express
+In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
+sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
- If you convey a covered work, knowingly relying on a patent license,
+If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
@@ -504,13 +393,13 @@ then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
+license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
- If, pursuant to or in connection with a single transaction or
+If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
@@ -518,10 +407,10 @@ or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
- A patent license is "discriminatory" if it does not include within
+A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
+specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
@@ -533,73 +422,73 @@ for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
- Nothing in this License shall be construed as excluding or limiting
+Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
- 12. No Surrender of Others' Freedom.
+12. No Surrender of Others' Freedom.
- If conditions are imposed on you (whether by court order, agreement or
+If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
+excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
+not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
- 13. Use with the GNU Affero General Public License.
+13. Use with the GNU Affero General Public License.
- Notwithstanding any other provision of this License, you have
+Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
+combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
- 14. Revised Versions of this License.
+14. Revised Versions of this License.
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
+The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
- Each version is given a distinguishing version number. If the
+Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
+Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
- If the Program specifies that a proxy can decide which future
+If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
+Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
- 15. Disclaimer of Warranty.
+15. Disclaimer of Warranty.
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
- 16. Limitation of Liability.
+16. Limitation of Liability.
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
@@ -609,9 +498,9 @@ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
- 17. Interpretation of Sections 15 and 16.
+17. Interpretation of Sections 15 and 16.
- If the disclaimer of warranty and limitation of liability provided
+If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
@@ -622,11 +511,11 @@ copy of the Program in return for a fee.
How to Apply These Terms to Your New Programs
- If you develop a new program, and you want it to be of the greatest
+If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
- To do so, attach the following notices to the program. It is safest
+To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
@@ -649,7 +538,7 @@ the "copyright" line and a pointer to where the full notice is found.
Also add information on how to contact you by electronic and paper mail.
- If the program does terminal interaction, make it output a short
+If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
@@ -658,17 +547,17 @@ notice like this when it starts in an interactive mode:
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
+parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
- You should also get your employer (if you work as a programmer) or school,
+You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
+The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
.
diff --git a/README.md b/README.md
index c0381c4..ed67ed6 100644
--- a/README.md
+++ b/README.md
@@ -354,6 +354,34 @@ This project is licensed under the [LICENSE](LICENSE) file in the repository.
+
+ Rujin Devkota
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ Adhavan K
+
+
+
+
+
+
+
+
+
+
+
+ |
diff --git a/SDUI_Flutter_Integration_Guide.txt b/SDUI_Flutter_Integration_Guide.txt
deleted file mode 100644
index 0519ecb..0000000
--- a/SDUI_Flutter_Integration_Guide.txt
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/docs/doc.md b/doc/doc.md
similarity index 100%
rename from docs/doc.md
rename to doc/doc.md
diff --git a/example/grpc_example.dart b/example/grpc_example.dart
index f0b699d..740f2eb 100644
--- a/example/grpc_example.dart
+++ b/example/grpc_example.dart
@@ -1,10 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter_sdui/flutter_sdui.dart';
+/// Example application demonstrating Flutter SDUI with gRPC.
+///
+/// This example shows how to:
+/// * Connect to a gRPC server
+/// * Fetch server-driven UI definitions
+/// * Render dynamic UI content
+/// * Handle different screen types
void main() {
runApp(const MyApp());
}
+/// Root application widget that sets up the Material theme and routing.
class MyApp extends StatelessWidget {
const MyApp({super.key});
@@ -21,6 +29,13 @@ class MyApp extends StatelessWidget {
}
}
+/// Demo widget that showcases the gRPC renderer functionality.
+///
+/// This widget demonstrates how to:
+/// * Initialize a gRPC client connection
+/// * Switch between different screen definitions
+/// * Handle loading and error states
+/// * Properly dispose of resources
class GrpcRendererDemo extends StatefulWidget {
const GrpcRendererDemo({super.key});
@@ -35,16 +50,16 @@ class _GrpcRendererDemoState extends State {
@override
void initState() {
super.initState();
- // Connect to your gRPC server
+ // Initialize gRPC client with server connection details
_grpcClient = SduiGrpcClient(
- host: 'localhost', // Replace with your server address
- port: 50051, // Replace with your server port
+ host: 'localhost',
+ port: 50051,
);
}
@override
void dispose() {
- // Close the gRPC connection when done
+ // Clean up gRPC connection
_grpcClient.dispose();
super.dispose();
}
@@ -57,7 +72,7 @@ class _GrpcRendererDemoState extends State {
),
body: Column(
children: [
- // Screen selector
+ // Screen selection controls
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
@@ -84,7 +99,7 @@ class _GrpcRendererDemoState extends State {
),
),
- // SDUI Renderer that fetches UI from gRPC server
+ // Server-driven UI renderer
Expanded(
child: SduiGrpcRenderer(
client: _grpcClient,
diff --git a/example/grpc_server_example_dart.dart b/example/grpc_server_example_dart.dart
index 4cec6f4..2cf54a3 100644
--- a/example/grpc_server_example_dart.dart
+++ b/example/grpc_server_example_dart.dart
@@ -1,9 +1,28 @@
-// Server implementation example (Dart)
-// Note: This is a standalone Dart server, not a Flutter application
-// Run with: dart run example/grpc_server_example.dart
+/// Example gRPC server implementation for Flutter SDUI.
+///
+/// This is a standalone Dart server that provides server-driven UI definitions
+/// through gRPC. It demonstrates how to:
+/// * Set up a gRPC server with SDUI service
+/// * Handle different screen requests
+/// * Create widget definitions using protobuf
+/// * Return complex UI structures
+///
+/// To run this server:
+/// ```bash
+/// dart run example/grpc_server_example_dart.dart
+/// ```
+///
+/// The server listens on port 50051 by default.
+library;
+import 'dart:developer';
+
import 'package:grpc/grpc.dart';
import 'package:flutter_sdui/src/generated/sdui.pbgrpc.dart';
+/// Entry point for the gRPC server.
+///
+/// Initializes the server with the SDUI service implementation
+/// and starts listening for client connections.
Future main() async {
final server = Server.create(
services: [
@@ -11,19 +30,22 @@ Future main() async {
],
);
- final port = 50051;
+ const port = 50051;
await server.serve(port: port);
- print('Server listening on port $port...');
- print('Press Ctrl+C to stop');
+ log('Server listening on port $port...');
+ log('Press Ctrl+C to stop');
}
-// Implementation of the SDUI service
+/// Implementation of the SDUI gRPC service.
+///
+/// This class handles incoming requests for UI definitions and returns
+/// appropriate widget data based on the requested screen ID.
class SduiServiceImpl extends SduiServiceBase {
@override
Future getSduiWidget(
ServiceCall call, SduiRequest request) async {
- // Based on the requested screen, return different UI definitions
- print('Received request for screen: ${request.screenId}');
+ log('Received request for screen: ${request.screenId}');
+
switch (request.screenId) {
case 'home':
return _createHomeScreen();
@@ -32,13 +54,14 @@ class SduiServiceImpl extends SduiServiceBase {
case 'settings':
return _createSettingsScreen();
default:
- // Default or error screen
- print('Warning: Unknown screen ID requested: ${request.screenId}');
+ log('Warning: Unknown screen ID requested: ${request.screenId}');
return _createErrorScreen();
}
}
- // Sample screen definitions
+ /// Creates the home screen UI definition.
+ ///
+ /// Returns a scaffold with an app bar and a column of welcome content.
SduiWidgetData _createHomeScreen() {
final homeScreen = SduiWidgetData()
..type = WidgetType.SCAFFOLD
diff --git a/lib/flutter_sdui.dart b/lib/flutter_sdui.dart
index a7e5442..5376a46 100644
--- a/lib/flutter_sdui.dart
+++ b/lib/flutter_sdui.dart
@@ -1,13 +1,34 @@
-/// Flutter SDUI Package
+/// Flutter Server-Driven UI Package
///
-/// A Flutter package to render server driven UI.
+/// A Flutter package that enables server-driven UI development by parsing
+/// protobuf-based widget definitions from a gRPC server and rendering them
+/// as native Flutter widgets.
+///
+/// This package provides:
+/// * Protobuf-based widget parsing and rendering
+/// * gRPC client for server communication
+/// * A comprehensive set of SDUI widgets that mirror Flutter's core widgets
+/// * Type-safe widget definitions through generated protobuf models
+///
+/// ## Usage
+///
+/// ```dart
+/// // Create a gRPC client
+/// final client = SduiGrpcClient(host: 'localhost', port: 50051);
+///
+/// // Render server-driven UI
+/// SduiGrpcRenderer(
+/// client: client,
+/// screenId: 'home',
+/// )
+/// ```
library;
-// Export the core parser and widget base
-export 'src/parser/sdui_proto_parser.dart'; // New proto parser
+// Core parsing and widget foundation
+export 'src/parser/sdui_proto_parser.dart';
export 'src/widgets/sdui_widget.dart';
-// Export individual widget models
+// SDUI widget implementations
export 'src/widgets/sdui_column.dart';
export 'src/widgets/sdui_row.dart';
export 'src/widgets/sdui_text.dart';
@@ -18,11 +39,11 @@ export 'src/widgets/sdui_scaffold.dart';
export 'src/widgets/sdui_spacer.dart';
export 'src/widgets/sdui_icon.dart';
-// Export gRPC client and renderer
+// Network communication
export 'src/service/sdui_grpc_client.dart';
export 'src/renderer/sdui_grpc_renderer.dart';
-// Export generated Protobuf models for public use
+// Generated protobuf models
export 'src/generated/sdui.pb.dart';
export 'src/generated/sdui.pbgrpc.dart';
export 'src/generated/sdui.pbenum.dart';
diff --git a/lib/src/parser/flutter_to_sdui.dart b/lib/src/parser/flutter_to_sdui.dart
index b3c23d2..8ed0903 100644
--- a/lib/src/parser/flutter_to_sdui.dart
+++ b/lib/src/parser/flutter_to_sdui.dart
@@ -50,7 +50,9 @@ SduiWidget flutterToSdui(Widget widget) {
width: widget.width,
height: widget.height,
fit: widget.fit,
- alignment: widget.alignment is Alignment ? widget.alignment as Alignment : null,
+ alignment: widget.alignment is Alignment
+ ? widget.alignment as Alignment
+ : null,
repeat: widget.repeat,
color: widget.color,
colorBlendMode: widget.colorBlendMode,
@@ -75,27 +77,40 @@ SduiWidget flutterToSdui(Widget widget) {
} else if (widget is Container) {
return SduiContainer(
child: widget.child != null ? flutterToSdui(widget.child!) : null,
- padding: widget.padding is EdgeInsets ? widget.padding as EdgeInsets : null,
+ padding:
+ widget.padding is EdgeInsets ? widget.padding as EdgeInsets : null,
margin: widget.margin is EdgeInsets ? widget.margin as EdgeInsets : null,
- decoration: widget.decoration is BoxDecoration ? widget.decoration as BoxDecoration : null,
+ decoration: widget.decoration is BoxDecoration
+ ? widget.decoration as BoxDecoration
+ : null,
width: null, // Container does not expose width directly
height: null, // Container does not expose height directly
color: widget.color,
- alignment: widget.alignment is Alignment ? widget.alignment as Alignment : null,
+ alignment:
+ widget.alignment is Alignment ? widget.alignment as Alignment : null,
constraints: widget.constraints,
transform: widget.transform,
- transformAlignment: widget.transformAlignment is AlignmentGeometry ? widget.transformAlignment as AlignmentGeometry : null,
+ transformAlignment: widget.transformAlignment is AlignmentGeometry
+ ? widget.transformAlignment as AlignmentGeometry
+ : null,
clipBehavior: widget.clipBehavior,
);
} else if (widget is Scaffold) {
return SduiScaffold(
appBar: widget.appBar != null ? flutterToSdui(widget.appBar!) : null,
body: widget.body != null ? flutterToSdui(widget.body!) : null,
- floatingActionButton: widget.floatingActionButton != null ? flutterToSdui(widget.floatingActionButton!) : null,
- bottomNavigationBar: widget.bottomNavigationBar != null ? flutterToSdui(widget.bottomNavigationBar!) : null,
+ floatingActionButton: widget.floatingActionButton != null
+ ? flutterToSdui(widget.floatingActionButton!)
+ : null,
+ bottomNavigationBar: widget.bottomNavigationBar != null
+ ? flutterToSdui(widget.bottomNavigationBar!)
+ : null,
drawer: widget.drawer != null ? flutterToSdui(widget.drawer!) : null,
- endDrawer: widget.endDrawer != null ? flutterToSdui(widget.endDrawer!) : null,
- bottomSheet: widget.bottomSheet != null ? flutterToSdui(widget.bottomSheet!) : null,
+ endDrawer:
+ widget.endDrawer != null ? flutterToSdui(widget.endDrawer!) : null,
+ bottomSheet: widget.bottomSheet != null
+ ? flutterToSdui(widget.bottomSheet!)
+ : null,
backgroundColor: widget.backgroundColor,
resizeToAvoidBottomInset: widget.resizeToAvoidBottomInset,
primary: widget.primary,
@@ -121,5 +136,6 @@ SduiWidget flutterToSdui(Widget widget) {
shadows: widget.shadows,
);
}
- throw UnimplementedError('Conversion for [38;5;9m${widget.runtimeType}[0m is not implemented');
-}
\ No newline at end of file
+ throw UnimplementedError(
+ 'Conversion for [38;5;9m${widget.runtimeType}[0m is not implemented');
+}
diff --git a/lib/src/parser/sdui_proto_parser.dart b/lib/src/parser/sdui_proto_parser.dart
index 64bbd10..ed34f5b 100644
--- a/lib/src/parser/sdui_proto_parser.dart
+++ b/lib/src/parser/sdui_proto_parser.dart
@@ -14,9 +14,26 @@ import 'package:flutter_sdui/src/widgets/sdui_spacer.dart';
import 'package:flutter_sdui/src/widgets/sdui_text.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-// Parser for Protobuf definitions for SDUI
+/// Parser for converting server-side widget definitions to SDUI widgets.
+///
+/// This class handles the conversion of protobuf-based widget definitions
+/// received from the server into corresponding SDUI widget instances that
+/// can be rendered in the Flutter application.
+///
+/// The parser supports various widget types and their properties, maintaining
+/// type safety through protobuf definitions while providing flexibility
+/// for server-driven UI updates.
class SduiParser {
- // Parse method for JSON data
+ /// Parses JSON data into SDUI widgets.
+ ///
+ /// This method is currently not implemented and will throw an
+ /// [UnimplementedError]. Future versions may support JSON-based
+ /// widget definitions as an alternative to protobuf.
+ ///
+ /// [data] - The JSON map containing widget definition
+ ///
+ /// Returns a parsed [SduiWidget] instance.
+ /// Throws [UnimplementedError] - JSON parsing is not yet supported.
static SduiWidget parseJSON(Map data) {
final String? type = data['type']?.toString().toLowerCase();
switch (type) {
@@ -43,7 +60,17 @@ class SduiParser {
}
}
- // Parse from Protobuf data model
+ /// Parses protobuf widget data into SDUI widgets.
+ ///
+ /// This is the main parsing method that converts server-provided protobuf
+ /// widget definitions into their corresponding SDUI widget instances.
+ /// The method uses a switch statement to determine the widget type and
+ /// delegates to specific parsing methods for each widget type.
+ ///
+ /// [data] - The protobuf widget data received from the server
+ ///
+ /// Returns a parsed [SduiWidget] instance, or [SduiContainer] if the
+ /// widget type is unsupported.
static SduiWidget parseProto(SduiWidgetData data) {
switch (data.type) {
case WidgetType.COLUMN:
@@ -70,9 +97,12 @@ class SduiParser {
}
}
- // Helper methods to parse specific widget types from protobuf
+ /// Parses protobuf data into a [SduiColumn] widget.
+ ///
+ /// Extracts all column-specific properties from the protobuf data
+ /// and recursively parses child widgets.
static SduiColumn _parseProtoColumn(SduiWidgetData data) {
- List children =
+ final List children =
data.children.map((child) => SduiParser.parseProto(child)).toList();
return SduiColumn(
@@ -87,8 +117,12 @@ class SduiParser {
);
}
+ /// Parses protobuf data into a [SduiRow] widget.
+ ///
+ /// Extracts all row-specific properties from the protobuf data
+ /// and recursively parses child widgets.
static SduiRow _parseProtoRow(SduiWidgetData data) {
- List children =
+ final List children =
data.children.map((child) => SduiParser.parseProto(child)).toList();
return SduiRow(
@@ -103,36 +137,52 @@ class SduiParser {
);
}
+ /// Parses protobuf data into a [SduiText] widget.
+ ///
+ /// Extracts text content and all styling properties from the protobuf data.
+ /// Text content is retrieved from the stringAttributes map, while styling
+ /// properties are parsed from individual fields.
static SduiText _parseProtoText(SduiWidgetData data) {
- String text = data.stringAttributes['text'] ?? '';
- TextStyle? style =
+ final String text = data.stringAttributes['text'] ?? '';
+ final TextStyle? style =
data.hasTextStyle() ? _parseProtoTextStyle(data.textStyle) : null;
- // Parse additional text properties
- TextAlign? textAlign = _parseProtoTextAlign(data.textAlign);
- TextOverflow? overflow = _parseProtoTextOverflow(data.overflow);
- int? maxLines = data.hasMaxLines() ? data.maxLines : null;
- bool? softWrap = data.hasSoftWrap() ? data.softWrap : null;
+ final TextAlign? textAlign = _parseProtoTextAlign(data.textAlign);
+ final TextOverflow? overflow = _parseProtoTextOverflow(data.overflow);
+ final int? maxLines = data.hasMaxLines() ? data.maxLines : null;
+ final bool? softWrap = data.hasSoftWrap() ? data.softWrap : null;
double? letterSpacing = data.hasLetterSpacing() ? data.letterSpacing : null;
double? wordSpacing = data.hasWordSpacing() ? data.wordSpacing : null;
double? height = data.hasHeight() ? data.height : null;
String? fontFamily = data.hasFontFamily() ? data.fontFamily : null;
- TextDirection? textDirection = _parseProtoTextDirection(data.textDirection);
+ final TextDirection? textDirection =
+ _parseProtoTextDirection(data.textDirection);
- // Extract from style if present
double? fontSize = style?.fontSize;
FontWeight? fontWeight = style?.fontWeight;
Color? color = style?.color;
TextDecoration? decoration = style?.decoration;
if (data.hasTextStyle()) {
if (data.textStyle.hasFontSize()) fontSize = data.textStyle.fontSize;
- if (data.textStyle.hasFontWeight()) fontWeight = _parseProtoFontWeight(data.textStyle.fontWeight);
- if (data.textStyle.hasColor()) color = _parseProtoColor(data.textStyle.color);
- if (data.textStyle.hasDecoration()) decoration = _parseProtoTextDecoration(data.textStyle.decoration);
- if (data.textStyle.hasLetterSpacing()) letterSpacing = data.textStyle.letterSpacing;
- if (data.textStyle.hasWordSpacing()) wordSpacing = data.textStyle.wordSpacing;
+ if (data.textStyle.hasFontWeight()) {
+ fontWeight = _parseProtoFontWeight(data.textStyle.fontWeight);
+ }
+ if (data.textStyle.hasColor()) {
+ color = _parseProtoColor(data.textStyle.color);
+ }
+ if (data.textStyle.hasDecoration()) {
+ decoration = _parseProtoTextDecoration(data.textStyle.decoration);
+ }
+ if (data.textStyle.hasLetterSpacing()) {
+ letterSpacing = data.textStyle.letterSpacing;
+ }
+ if (data.textStyle.hasWordSpacing()) {
+ wordSpacing = data.textStyle.wordSpacing;
+ }
if (data.textStyle.hasHeight()) height = data.textStyle.height;
- if (data.textStyle.hasFontFamily()) fontFamily = data.textStyle.fontFamily;
+ if (data.textStyle.hasFontFamily()) {
+ fontFamily = data.textStyle.fontFamily;
+ }
}
return SduiText(
@@ -154,34 +204,38 @@ class SduiParser {
);
}
+ /// Parses protobuf data into a [SduiImage] widget.
+ ///
+ /// Extracts image source URL and all display properties including sizing,
+ /// alignment, color blending, and caching options.
static SduiImage _parseProtoImage(SduiWidgetData data) {
- String src = data.stringAttributes['src'] ?? '';
- double? width = data.doubleAttributes['width'];
- double? height = data.doubleAttributes['height'];
- BoxFit? fit = _parseProtoBoxFit(data.stringAttributes['fit']);
-
- // Parse additional image properties
- Alignment? alignment = _parseProtoAlignment(data.alignment);
- ImageRepeat? repeat = _parseProtoImageRepeat(data.repeat);
- Color? color = data.hasColor() ? _parseProtoColor(data.color) : null;
- BlendMode? colorBlendMode = _parseProtoBlendMode(data.colorBlendMode);
- Rect? centerSlice =
+ final String src = data.stringAttributes['src'] ?? '';
+ final double? width = data.doubleAttributes['width'];
+ final double? height = data.doubleAttributes['height'];
+ final BoxFit? fit = _parseProtoBoxFit(data.stringAttributes['fit']);
+
+ final Alignment? alignment = _parseProtoAlignment(data.alignment);
+ final ImageRepeat? repeat = _parseProtoImageRepeat(data.repeat);
+ final Color? color = data.hasColor() ? _parseProtoColor(data.color) : null;
+ final BlendMode? colorBlendMode = _parseProtoBlendMode(data.colorBlendMode);
+ final Rect? centerSlice =
data.hasCenterSlice() ? _parseProtoRect(data.centerSlice) : null;
- bool? matchTextDirection =
+ final bool? matchTextDirection =
data.hasMatchTextDirection() ? data.matchTextDirection : null;
- bool? gaplessPlayback =
+ final bool? gaplessPlayback =
data.hasGaplessPlayback() ? data.gaplessPlayback : null;
- FilterQuality? filterQuality = _parseProtoFilterQuality(data.filterQuality);
- int? cacheWidth = data.hasCacheWidth() ? data.cacheWidth : null;
- int? cacheHeight = data.hasCacheHeight() ? data.cacheHeight : null;
- double? scale = data.hasScale() ? data.scale : null;
- String? semanticLabel = data.hasSemanticLabel() ? data.semanticLabel : null;
-
- // Parse error and loading widgets
- Widget? errorWidget = data.hasErrorWidget()
+ final FilterQuality? filterQuality =
+ _parseProtoFilterQuality(data.filterQuality);
+ final int? cacheWidth = data.hasCacheWidth() ? data.cacheWidth : null;
+ final int? cacheHeight = data.hasCacheHeight() ? data.cacheHeight : null;
+ final double? scale = data.hasScale() ? data.scale : null;
+ final String? semanticLabel =
+ data.hasSemanticLabel() ? data.semanticLabel : null;
+
+ final Widget? errorWidget = data.hasErrorWidget()
? SduiParser.parseProto(data.errorWidget).toFlutterWidget()
: null;
- Widget? loadingWidget = data.hasLoadingWidget()
+ final Widget? loadingWidget = data.hasLoadingWidget()
? SduiParser.parseProto(data.loadingWidget).toFlutterWidget()
: null;
@@ -229,7 +283,6 @@ class SduiParser {
double? height = data.doubleAttributes['height'];
Color? color = data.hasColor() ? _parseProtoColor(data.color) : null;
- // Parse additional container properties
Alignment? alignment = _parseProtoAlignment(data.alignment);
BoxConstraints? constraints = data.hasConstraints()
? _parseProtoBoxConstraints(data.constraints)
@@ -268,7 +321,6 @@ class SduiParser {
? _parseProtoColor(data.backgroundColor)
: null;
- // Parse additional scaffold properties
SduiWidget? bottomNavigationBar = data.hasBottomNavigationBar()
? SduiParser.parseProto(data.bottomNavigationBar)
: null;
@@ -334,7 +386,6 @@ class SduiParser {
Color? color =
data.icon.hasColor() ? _parseProtoColor(data.icon.color) : null;
- // Parse additional icon properties
String? semanticLabel = data.hasSemanticLabel() ? data.semanticLabel : null;
TextDirection? textDirection = _parseProtoTextDirection(data.textDirection);
double? opacity = data.hasOpacity() ? data.opacity : null;
@@ -356,8 +407,12 @@ class SduiParser {
);
}
- // Helper methods for parsing protobuf attribute types
+ /// Helper methods for parsing protobuf attribute types into Flutter types.
+ /// Parses a string value into a [BoxFit] enum.
+ ///
+ /// Supports common box fit values like 'fill', 'contain', 'cover', etc.
+ /// Returns null if the value is null or unrecognized.
static BoxFit? _parseProtoBoxFit(String? value) {
if (value == null) return null;
switch (value.toLowerCase()) {
@@ -380,16 +435,22 @@ class SduiParser {
}
}
+ /// Parses protobuf text style data into a Flutter [TextStyle].
+ ///
+ /// Converts all text styling properties from protobuf format
+ /// to their corresponding Flutter TextStyle properties.
static TextStyle? _parseProtoTextStyle(TextStyleData data) {
- Color? color = data.hasColor() ? _parseProtoColor(data.color) : null;
- double? fontSize = data.fontSize;
- FontWeight? fontWeight = _parseProtoFontWeight(data.fontWeight);
- TextDecoration? decoration = _parseProtoTextDecoration(data.decoration);
- double? letterSpacing = data.hasLetterSpacing() ? data.letterSpacing : null;
- double? wordSpacing = data.hasWordSpacing() ? data.wordSpacing : null;
- double? height = data.hasHeight() ? data.height : null;
- String? fontFamily = data.hasFontFamily() ? data.fontFamily : null;
- FontStyle? fontStyle = _parseProtoFontStyle(data.fontStyle);
+ final Color? color = data.hasColor() ? _parseProtoColor(data.color) : null;
+ final double fontSize = data.fontSize;
+ final FontWeight? fontWeight = _parseProtoFontWeight(data.fontWeight);
+ final TextDecoration? decoration =
+ _parseProtoTextDecoration(data.decoration);
+ final double? letterSpacing =
+ data.hasLetterSpacing() ? data.letterSpacing : null;
+ final double? wordSpacing = data.hasWordSpacing() ? data.wordSpacing : null;
+ final double? height = data.hasHeight() ? data.height : null;
+ final String? fontFamily = data.hasFontFamily() ? data.fontFamily : null;
+ final FontStyle? fontStyle = _parseProtoFontStyle(data.fontStyle);
return TextStyle(
color: color,
@@ -404,6 +465,10 @@ class SduiParser {
);
}
+ /// Parses a string value into a [FontWeight] enum.
+ ///
+ /// Supports both named weights ('bold', 'normal') and numeric weights
+ /// ('w100' through 'w900'). Returns null for unrecognized values.
static FontWeight? _parseProtoFontWeight(String? value) {
if (value == null) return null;
switch (value.toLowerCase()) {
@@ -434,6 +499,10 @@ class SduiParser {
}
}
+ /// Parses protobuf edge insets data into Flutter [EdgeInsets].
+ ///
+ /// Supports both uniform insets (all sides equal) and individual
+ /// side specifications (left, top, right, bottom).
static EdgeInsets? _parseProtoEdgeInsets(EdgeInsetsData data) {
if (data.hasAll()) {
return EdgeInsets.all(data.all);
@@ -447,6 +516,10 @@ class SduiParser {
);
}
+ /// Parses protobuf color data into a Flutter [Color].
+ ///
+ /// Creates a Color from ARGB values provided in the protobuf data.
+ /// Alpha, red, green, and blue values should be in the range 0-255.
static Color? _parseProtoColor(ColorData data) {
return Color.fromARGB(
data.alpha,
@@ -527,7 +600,7 @@ class SduiParser {
);
}
- return BorderRadius.circular(8.0); // Example default value
+ return BorderRadius.circular(8.0);
}
// New helper methods for parsing new property types
@@ -873,7 +946,8 @@ class SduiParser {
return SduiColumn(
children: children,
mainAxisAlignment: _parseJsonMainAxisAlignment(data['mainAxisAlignment']),
- crossAxisAlignment: _parseJsonCrossAxisAlignment(data['crossAxisAlignment']),
+ crossAxisAlignment:
+ _parseJsonCrossAxisAlignment(data['crossAxisAlignment']),
mainAxisSize: _parseJsonMainAxisSize(data['mainAxisSize']),
textDirection: _parseJsonTextDirection(data['textDirection']),
verticalDirection: _parseJsonVerticalDirection(data['verticalDirection']),
@@ -977,7 +1051,8 @@ class SduiParser {
return SduiRow(
children: children,
mainAxisAlignment: _parseJsonMainAxisAlignment(data['mainAxisAlignment']),
- crossAxisAlignment: _parseJsonCrossAxisAlignment(data['crossAxisAlignment']),
+ crossAxisAlignment:
+ _parseJsonCrossAxisAlignment(data['crossAxisAlignment']),
mainAxisSize: _parseJsonMainAxisSize(data['mainAxisSize']),
textDirection: _parseJsonTextDirection(data['textDirection']),
verticalDirection: _parseJsonVerticalDirection(data['verticalDirection']),
@@ -991,91 +1066,145 @@ class SduiParser {
style: _parseJsonTextStyle(data['style']),
textAlign: _parseJsonTextAlign(data['textAlign']),
overflow: _parseJsonTextOverflow(data['overflow']),
- maxLines: data['maxLines'] is int ? data['maxLines'] : int.tryParse(data['maxLines']?.toString() ?? ''),
+ maxLines: data['maxLines'] is int
+ ? data['maxLines']
+ : int.tryParse(data['maxLines']?.toString() ?? ''),
softWrap: data['softWrap'] is bool ? data['softWrap'] : null,
- letterSpacing: (data['letterSpacing'] is num) ? (data['letterSpacing'] as num).toDouble() : null,
- wordSpacing: (data['wordSpacing'] is num) ? (data['wordSpacing'] as num).toDouble() : null,
- height: (data['height'] is num) ? (data['height'] as num).toDouble() : null,
+ letterSpacing: (data['letterSpacing'] is num)
+ ? (data['letterSpacing'] as num).toDouble()
+ : null,
+ wordSpacing: (data['wordSpacing'] is num)
+ ? (data['wordSpacing'] as num).toDouble()
+ : null,
+ height:
+ (data['height'] is num) ? (data['height'] as num).toDouble() : null,
fontFamily: data['fontFamily']?.toString(),
textDirection: _parseJsonTextDirection(data['textDirection']),
);
}
static SduiImage _parseJsonImage(Map data) {
- SduiWidget? errorSduiWidget = data['errorWidget'] is Map ? parseJSON(data['errorWidget']) : null;
- SduiWidget? loadingSduiWidget = data['loadingWidget'] is Map ? parseJSON(data['loadingWidget']) : null;
+ SduiWidget? errorSduiWidget = data['errorWidget'] is Map
+ ? parseJSON(data['errorWidget'])
+ : null;
+ SduiWidget? loadingSduiWidget =
+ data['loadingWidget'] is Map
+ ? parseJSON(data['loadingWidget'])
+ : null;
return SduiImage(
data['src']?.toString() ?? '',
width: (data['width'] is num) ? (data['width'] as num).toDouble() : null,
- height: (data['height'] is num) ? (data['height'] as num).toDouble() : null,
+ height:
+ (data['height'] is num) ? (data['height'] as num).toDouble() : null,
fit: _parseJsonBoxFit(data['fit']),
alignment: _parseJsonAlignment(data['alignment']),
repeat: _parseJsonImageRepeat(data['repeat']),
color: _parseJsonColor(data['color']),
colorBlendMode: _parseJsonBlendMode(data['colorBlendMode']),
centerSlice: _parseJsonRect(data['centerSlice']),
- matchTextDirection: data['matchTextDirection'] is bool ? data['matchTextDirection'] : null,
- gaplessPlayback: data['gaplessPlayback'] is bool ? data['gaplessPlayback'] : null,
+ matchTextDirection: data['matchTextDirection'] is bool
+ ? data['matchTextDirection']
+ : null,
+ gaplessPlayback:
+ data['gaplessPlayback'] is bool ? data['gaplessPlayback'] : null,
filterQuality: _parseJsonFilterQuality(data['filterQuality']),
- cacheWidth: data['cacheWidth'] is int ? data['cacheWidth'] : int.tryParse(data['cacheWidth']?.toString() ?? ''),
- cacheHeight: data['cacheHeight'] is int ? data['cacheHeight'] : int.tryParse(data['cacheHeight']?.toString() ?? ''),
+ cacheWidth: data['cacheWidth'] is int
+ ? data['cacheWidth']
+ : int.tryParse(data['cacheWidth']?.toString() ?? ''),
+ cacheHeight: data['cacheHeight'] is int
+ ? data['cacheHeight']
+ : int.tryParse(data['cacheHeight']?.toString() ?? ''),
scale: (data['scale'] is num) ? (data['scale'] as num).toDouble() : null,
semanticLabel: data['semanticLabel']?.toString(),
- errorWidget: errorSduiWidget != null ? errorSduiWidget.toFlutterWidget() : null,
- loadingWidget: loadingSduiWidget != null ? loadingSduiWidget.toFlutterWidget() : null,
+ errorWidget: errorSduiWidget?.toFlutterWidget(),
+ loadingWidget: loadingSduiWidget?.toFlutterWidget(),
);
}
static SduiSizedBox _parseJsonSizedBox(Map data) {
return SduiSizedBox(
width: (data['width'] is num) ? (data['width'] as num).toDouble() : null,
- height: (data['height'] is num) ? (data['height'] as num).toDouble() : null,
- child: data['child'] is Map ? parseJSON(data['child']) : null,
+ height:
+ (data['height'] is num) ? (data['height'] as num).toDouble() : null,
+ child: data['child'] is Map
+ ? parseJSON(data['child'])
+ : null,
);
}
static SduiContainer _parseJsonContainer(Map data) {
return SduiContainer(
- child: data['child'] is Map ? parseJSON(data['child']) : null,
+ child: data['child'] is Map
+ ? parseJSON(data['child'])
+ : null,
padding: _parseJsonEdgeInsets(data['padding']),
margin: _parseJsonEdgeInsets(data['margin']),
decoration: _parseJsonBoxDecoration(data['decoration']),
width: (data['width'] is num) ? (data['width'] as num).toDouble() : null,
- height: (data['height'] is num) ? (data['height'] as num).toDouble() : null,
+ height:
+ (data['height'] is num) ? (data['height'] as num).toDouble() : null,
color: _parseJsonColor(data['color']),
alignment: _parseJsonAlignment(data['alignment']),
constraints: _parseJsonBoxConstraints(data['constraints']),
transform: _parseJsonTransform(data['transform']),
- transformAlignment: _parseJsonAlignmentGeometry(data['transformAlignment']),
+ transformAlignment:
+ _parseJsonAlignmentGeometry(data['transformAlignment']),
clipBehavior: _parseJsonClip(data['clipBehavior']),
);
}
static SduiScaffold _parseJsonScaffold(Map data) {
return SduiScaffold(
- appBar: data['appBar'] is Map ? parseJSON(data['appBar']) : null,
- body: data['body'] is Map ? parseJSON(data['body']) : null,
- floatingActionButton: data['floatingActionButton'] is Map ? parseJSON(data['floatingActionButton']) : null,
- bottomNavigationBar: data['bottomNavigationBar'] is Map ? parseJSON(data['bottomNavigationBar']) : null,
- drawer: data['drawer'] is Map ? parseJSON(data['drawer']) : null,
- endDrawer: data['endDrawer'] is Map ? parseJSON(data['endDrawer']) : null,
- bottomSheet: data['bottomSheet'] is Map ? parseJSON(data['bottomSheet']) : null,
+ appBar: data['appBar'] is Map
+ ? parseJSON(data['appBar'])
+ : null,
+ body:
+ data['body'] is Map ? parseJSON(data['body']) : null,
+ floatingActionButton: data['floatingActionButton'] is Map
+ ? parseJSON(data['floatingActionButton'])
+ : null,
+ bottomNavigationBar: data['bottomNavigationBar'] is Map
+ ? parseJSON(data['bottomNavigationBar'])
+ : null,
+ drawer: data['drawer'] is Map
+ ? parseJSON(data['drawer'])
+ : null,
+ endDrawer: data['endDrawer'] is Map
+ ? parseJSON(data['endDrawer'])
+ : null,
+ bottomSheet: data['bottomSheet'] is Map
+ ? parseJSON(data['bottomSheet'])
+ : null,
backgroundColor: _parseJsonColor(data['backgroundColor']),
- resizeToAvoidBottomInset: data['resizeToAvoidBottomInset'] is bool ? data['resizeToAvoidBottomInset'] : null,
+ resizeToAvoidBottomInset: data['resizeToAvoidBottomInset'] is bool
+ ? data['resizeToAvoidBottomInset']
+ : null,
primary: data['primary'] is bool ? data['primary'] : null,
- floatingActionButtonLocation: _parseJsonFabLocation(data['floatingActionButtonLocation']),
+ floatingActionButtonLocation:
+ _parseJsonFabLocation(data['floatingActionButtonLocation']),
extendBody: data['extendBody'] is bool ? data['extendBody'] : null,
- extendBodyBehindAppBar: data['extendBodyBehindAppBar'] is bool ? data['extendBodyBehindAppBar'] : null,
+ extendBodyBehindAppBar: data['extendBodyBehindAppBar'] is bool
+ ? data['extendBodyBehindAppBar']
+ : null,
drawerScrimColor: _parseJsonColor(data['drawerScrimColor']),
- drawerEdgeDragWidth: (data['drawerEdgeDragWidth'] is num) ? (data['drawerEdgeDragWidth'] as num).toDouble() : null,
- drawerEnableOpenDragGesture: data['drawerEnableOpenDragGesture'] is bool ? data['drawerEnableOpenDragGesture'] : null,
- endDrawerEnableOpenDragGesture: data['endDrawerEnableOpenDragGesture'] is bool ? data['endDrawerEnableOpenDragGesture'] : null,
+ drawerEdgeDragWidth: (data['drawerEdgeDragWidth'] is num)
+ ? (data['drawerEdgeDragWidth'] as num).toDouble()
+ : null,
+ drawerEnableOpenDragGesture: data['drawerEnableOpenDragGesture'] is bool
+ ? data['drawerEnableOpenDragGesture']
+ : null,
+ endDrawerEnableOpenDragGesture:
+ data['endDrawerEnableOpenDragGesture'] is bool
+ ? data['endDrawerEnableOpenDragGesture']
+ : null,
);
}
static SduiSpacer _parseJsonSpacer(Map data) {
return SduiSpacer(
- flex: data['flex'] is int ? data['flex'] : int.tryParse(data['flex']?.toString() ?? '') ?? 1,
+ flex: data['flex'] is int
+ ? data['flex']
+ : int.tryParse(data['flex']?.toString() ?? '') ?? 1,
);
}
@@ -1086,8 +1215,10 @@ class SduiParser {
color: _parseJsonColor(data['color']),
semanticLabel: data['semanticLabel']?.toString(),
textDirection: _parseJsonTextDirection(data['textDirection']),
- opacity: (data['opacity'] is num) ? (data['opacity'] as num).toDouble() : null,
- applyTextScaling: data['applyTextScaling'] is bool ? data['applyTextScaling'] : null,
+ opacity:
+ (data['opacity'] is num) ? (data['opacity'] as num).toDouble() : null,
+ applyTextScaling:
+ data['applyTextScaling'] is bool ? data['applyTextScaling'] : null,
shadows: _parseJsonShadows(data['shadows']),
);
}
@@ -1097,12 +1228,19 @@ class SduiParser {
if (value is! Map) return null;
return TextStyle(
color: _parseJsonColor(value['color']),
- fontSize: (value['fontSize'] is num) ? (value['fontSize'] as num).toDouble() : null,
+ fontSize: (value['fontSize'] is num)
+ ? (value['fontSize'] as num).toDouble()
+ : null,
fontWeight: _parseJsonFontWeight(value['fontWeight']),
decoration: _parseJsonTextDecoration(value['decoration']),
- letterSpacing: (value['letterSpacing'] is num) ? (value['letterSpacing'] as num).toDouble() : null,
- wordSpacing: (value['wordSpacing'] is num) ? (value['wordSpacing'] as num).toDouble() : null,
- height: (value['height'] is num) ? (value['height'] as num).toDouble() : null,
+ letterSpacing: (value['letterSpacing'] is num)
+ ? (value['letterSpacing'] as num).toDouble()
+ : null,
+ wordSpacing: (value['wordSpacing'] is num)
+ ? (value['wordSpacing'] as num).toDouble()
+ : null,
+ height:
+ (value['height'] is num) ? (value['height'] as num).toDouble() : null,
fontFamily: value['fontFamily']?.toString(),
fontStyle: _parseJsonFontStyle(value['fontStyle']),
);
@@ -1315,48 +1453,78 @@ class SduiParser {
static BlendMode? _parseJsonBlendMode(dynamic value) {
if (value == null) return null;
switch (value.toString().toLowerCase()) {
- case 'clear': return BlendMode.clear;
- case 'src': return BlendMode.src;
- case 'dst': return BlendMode.dst;
+ case 'clear':
+ return BlendMode.clear;
+ case 'src':
+ return BlendMode.src;
+ case 'dst':
+ return BlendMode.dst;
case 'srcover':
- case 'src_over': return BlendMode.srcOver;
+ case 'src_over':
+ return BlendMode.srcOver;
case 'dstover':
- case 'dst_over': return BlendMode.dstOver;
+ case 'dst_over':
+ return BlendMode.dstOver;
case 'srcin':
- case 'src_in': return BlendMode.srcIn;
+ case 'src_in':
+ return BlendMode.srcIn;
case 'dstin':
- case 'dst_in': return BlendMode.dstIn;
+ case 'dst_in':
+ return BlendMode.dstIn;
case 'srcout':
- case 'src_out': return BlendMode.srcOut;
+ case 'src_out':
+ return BlendMode.srcOut;
case 'dstout':
- case 'dst_out': return BlendMode.dstOut;
+ case 'dst_out':
+ return BlendMode.dstOut;
case 'srcatop':
- case 'src_atop': return BlendMode.srcATop;
+ case 'src_atop':
+ return BlendMode.srcATop;
case 'dstatop':
- case 'dst_atop': return BlendMode.dstATop;
- case 'xor': return BlendMode.xor;
- case 'plus': return BlendMode.plus;
- case 'modulate': return BlendMode.modulate;
- case 'screen': return BlendMode.screen;
- case 'overlay': return BlendMode.overlay;
- case 'darken': return BlendMode.darken;
- case 'lighten': return BlendMode.lighten;
+ case 'dst_atop':
+ return BlendMode.dstATop;
+ case 'xor':
+ return BlendMode.xor;
+ case 'plus':
+ return BlendMode.plus;
+ case 'modulate':
+ return BlendMode.modulate;
+ case 'screen':
+ return BlendMode.screen;
+ case 'overlay':
+ return BlendMode.overlay;
+ case 'darken':
+ return BlendMode.darken;
+ case 'lighten':
+ return BlendMode.lighten;
case 'colordodge':
- case 'color_dodge': return BlendMode.colorDodge;
+ case 'color_dodge':
+ return BlendMode.colorDodge;
case 'colorburn':
- case 'color_burn': return BlendMode.colorBurn;
+ case 'color_burn':
+ return BlendMode.colorBurn;
case 'hardlight':
- case 'hard_light': return BlendMode.hardLight;
+ case 'hard_light':
+ return BlendMode.hardLight;
case 'softlight':
- case 'soft_light': return BlendMode.softLight;
- case 'difference': return BlendMode.difference;
- case 'exclusion': return BlendMode.exclusion;
- case 'multiply': return BlendMode.multiply;
- case 'hue': return BlendMode.hue;
- case 'saturation': return BlendMode.saturation;
- case 'color': return BlendMode.color;
- case 'luminosity': return BlendMode.luminosity;
- default: return null;
+ case 'soft_light':
+ return BlendMode.softLight;
+ case 'difference':
+ return BlendMode.difference;
+ case 'exclusion':
+ return BlendMode.exclusion;
+ case 'multiply':
+ return BlendMode.multiply;
+ case 'hue':
+ return BlendMode.hue;
+ case 'saturation':
+ return BlendMode.saturation;
+ case 'color':
+ return BlendMode.color;
+ case 'luminosity':
+ return BlendMode.luminosity;
+ default:
+ return null;
}
}
@@ -1375,11 +1543,16 @@ class SduiParser {
static FilterQuality? _parseJsonFilterQuality(dynamic value) {
if (value == null) return null;
switch (value.toString().toLowerCase()) {
- case 'none': return FilterQuality.none;
- case 'low': return FilterQuality.low;
- case 'medium': return FilterQuality.medium;
- case 'high': return FilterQuality.high;
- default: return null;
+ case 'none':
+ return FilterQuality.none;
+ case 'low':
+ return FilterQuality.low;
+ case 'medium':
+ return FilterQuality.medium;
+ case 'high':
+ return FilterQuality.high;
+ default:
+ return null;
}
}
@@ -1391,8 +1564,11 @@ class SduiParser {
return EdgeInsets.only(
left: (value['left'] is num) ? (value['left'] as num).toDouble() : 0.0,
top: (value['top'] is num) ? (value['top'] as num).toDouble() : 0.0,
- right: (value['right'] is num) ? (value['right'] as num).toDouble() : 0.0,
- bottom: (value['bottom'] is num) ? (value['bottom'] as num).toDouble() : 0.0,
+ right:
+ (value['right'] is num) ? (value['right'] as num).toDouble() : 0.0,
+ bottom: (value['bottom'] is num)
+ ? (value['bottom'] as num).toDouble()
+ : 0.0,
);
}
return null;
@@ -1410,13 +1586,22 @@ class SduiParser {
static BorderRadius? _parseJsonBorderRadius(dynamic value) {
if (value is Map) {
if (value.containsKey('all')) {
- return BorderRadius.all(Radius.circular((value['all'] as num).toDouble()));
+ return BorderRadius.all(
+ Radius.circular((value['all'] as num).toDouble()));
}
return BorderRadius.only(
- topLeft: value['topLeft'] != null ? Radius.circular((value['topLeft'] as num).toDouble()) : Radius.zero,
- topRight: value['topRight'] != null ? Radius.circular((value['topRight'] as num).toDouble()) : Radius.zero,
- bottomLeft: value['bottomLeft'] != null ? Radius.circular((value['bottomLeft'] as num).toDouble()) : Radius.zero,
- bottomRight: value['bottomRight'] != null ? Radius.circular((value['bottomRight'] as num).toDouble()) : Radius.zero,
+ topLeft: value['topLeft'] != null
+ ? Radius.circular((value['topLeft'] as num).toDouble())
+ : Radius.zero,
+ topRight: value['topRight'] != null
+ ? Radius.circular((value['topRight'] as num).toDouble())
+ : Radius.zero,
+ bottomLeft: value['bottomLeft'] != null
+ ? Radius.circular((value['bottomLeft'] as num).toDouble())
+ : Radius.zero,
+ bottomRight: value['bottomRight'] != null
+ ? Radius.circular((value['bottomRight'] as num).toDouble())
+ : Radius.zero,
);
}
return null;
@@ -1425,10 +1610,18 @@ class SduiParser {
static BoxConstraints? _parseJsonBoxConstraints(dynamic value) {
if (value is Map) {
return BoxConstraints(
- minWidth: (value['minWidth'] is num) ? (value['minWidth'] as num).toDouble() : 0.0,
- maxWidth: (value['maxWidth'] is num) ? (value['maxWidth'] as num).toDouble() : double.infinity,
- minHeight: (value['minHeight'] is num) ? (value['minHeight'] as num).toDouble() : 0.0,
- maxHeight: (value['maxHeight'] is num) ? (value['maxHeight'] as num).toDouble() : double.infinity,
+ minWidth: (value['minWidth'] is num)
+ ? (value['minWidth'] as num).toDouble()
+ : 0.0,
+ maxWidth: (value['maxWidth'] is num)
+ ? (value['maxWidth'] as num).toDouble()
+ : double.infinity,
+ minHeight: (value['minHeight'] is num)
+ ? (value['minHeight'] as num).toDouble()
+ : 0.0,
+ maxHeight: (value['maxHeight'] is num)
+ ? (value['maxHeight'] as num).toDouble()
+ : double.infinity,
);
}
return null;
@@ -1440,10 +1633,22 @@ class SduiParser {
final vals = value['matrixValues'] as List;
if (vals.length == 16) {
return Matrix4(
- (vals[0] as num).toDouble(), (vals[1] as num).toDouble(), (vals[2] as num).toDouble(), (vals[3] as num).toDouble(),
- (vals[4] as num).toDouble(), (vals[5] as num).toDouble(), (vals[6] as num).toDouble(), (vals[7] as num).toDouble(),
- (vals[8] as num).toDouble(), (vals[9] as num).toDouble(), (vals[10] as num).toDouble(), (vals[11] as num).toDouble(),
- (vals[12] as num).toDouble(), (vals[13] as num).toDouble(), (vals[14] as num).toDouble(), (vals[15] as num).toDouble(),
+ (vals[0] as num).toDouble(),
+ (vals[1] as num).toDouble(),
+ (vals[2] as num).toDouble(),
+ (vals[3] as num).toDouble(),
+ (vals[4] as num).toDouble(),
+ (vals[5] as num).toDouble(),
+ (vals[6] as num).toDouble(),
+ (vals[7] as num).toDouble(),
+ (vals[8] as num).toDouble(),
+ (vals[9] as num).toDouble(),
+ (vals[10] as num).toDouble(),
+ (vals[11] as num).toDouble(),
+ (vals[12] as num).toDouble(),
+ (vals[13] as num).toDouble(),
+ (vals[14] as num).toDouble(),
+ (vals[15] as num).toDouble(),
);
}
} else if (value['type'] == 'translate') {
@@ -1472,13 +1677,18 @@ class SduiParser {
static Clip? _parseJsonClip(dynamic value) {
if (value == null) return null;
switch (value.toString().toLowerCase()) {
- case 'none': return Clip.none;
+ case 'none':
+ return Clip.none;
case 'hardedge':
- case 'hard_edge': return Clip.hardEdge;
- case 'antialias': return Clip.antiAlias;
+ case 'hard_edge':
+ return Clip.hardEdge;
+ case 'antialias':
+ return Clip.antiAlias;
case 'antialiaswithsavelayer':
- case 'antialias_with_save_layer': return Clip.antiAliasWithSaveLayer;
- default: return null;
+ case 'antialias_with_save_layer':
+ return Clip.antiAliasWithSaveLayer;
+ default:
+ return null;
}
}
@@ -1486,33 +1696,46 @@ class SduiParser {
if (value == null) return null;
switch (value.toString().toLowerCase()) {
case 'starttop':
- case 'start_top': return FloatingActionButtonLocation.startTop;
+ case 'start_top':
+ return FloatingActionButtonLocation.startTop;
case 'start':
case 'startfloat':
- case 'start_float': return FloatingActionButtonLocation.startFloat;
+ case 'start_float':
+ return FloatingActionButtonLocation.startFloat;
case 'centertop':
- case 'center_top': return FloatingActionButtonLocation.centerTop;
+ case 'center_top':
+ return FloatingActionButtonLocation.centerTop;
case 'center':
case 'centerfloat':
- case 'center_float': return FloatingActionButtonLocation.centerFloat;
+ case 'center_float':
+ return FloatingActionButtonLocation.centerFloat;
case 'endtop':
- case 'end_top': return FloatingActionButtonLocation.endTop;
+ case 'end_top':
+ return FloatingActionButtonLocation.endTop;
case 'end':
case 'endfloat':
- case 'end_float': return FloatingActionButtonLocation.endFloat;
+ case 'end_float':
+ return FloatingActionButtonLocation.endFloat;
case 'minicentertop':
- case 'mini_center_top': return FloatingActionButtonLocation.miniCenterTop;
+ case 'mini_center_top':
+ return FloatingActionButtonLocation.miniCenterTop;
case 'minicenterfloat':
- case 'mini_center_float': return FloatingActionButtonLocation.miniCenterFloat;
+ case 'mini_center_float':
+ return FloatingActionButtonLocation.miniCenterFloat;
case 'ministarttop':
- case 'mini_start_top': return FloatingActionButtonLocation.miniStartTop;
+ case 'mini_start_top':
+ return FloatingActionButtonLocation.miniStartTop;
case 'ministartfloat':
- case 'mini_start_float': return FloatingActionButtonLocation.miniStartFloat;
+ case 'mini_start_float':
+ return FloatingActionButtonLocation.miniStartFloat;
case 'miniendtop':
- case 'mini_end_top': return FloatingActionButtonLocation.miniEndTop;
+ case 'mini_end_top':
+ return FloatingActionButtonLocation.miniEndTop;
case 'miniendfloat':
- case 'mini_end_float': return FloatingActionButtonLocation.miniEndFloat;
- default: return null;
+ case 'mini_end_float':
+ return FloatingActionButtonLocation.miniEndFloat;
+ default:
+ return null;
}
}
@@ -1520,27 +1743,41 @@ class SduiParser {
if (value == null) return null;
if (value is String) {
switch (value.toLowerCase()) {
- case 'settings': return Icons.settings;
- case 'home': return Icons.home;
- case 'search': return Icons.search;
- case 'add': return Icons.add;
- case 'edit': return Icons.edit;
- default: break;
+ case 'settings':
+ return Icons.settings;
+ case 'home':
+ return Icons.home;
+ case 'search':
+ return Icons.search;
+ case 'add':
+ return Icons.add;
+ case 'edit':
+ return Icons.edit;
+ default:
+ break;
}
} else if (value is Map) {
if (value['name'] != null) {
switch (value['name'].toString().toLowerCase()) {
- case 'settings': return Icons.settings;
- case 'home': return Icons.home;
- case 'search': return Icons.search;
- case 'add': return Icons.add;
- case 'edit': return Icons.edit;
- default: break;
+ case 'settings':
+ return Icons.settings;
+ case 'home':
+ return Icons.home;
+ case 'search':
+ return Icons.search;
+ case 'add':
+ return Icons.add;
+ case 'edit':
+ return Icons.edit;
+ default:
+ break;
}
}
if (value['codePoint'] != null) {
return IconData(
- value['codePoint'] is int ? value['codePoint'] : int.tryParse(value['codePoint'].toString()) ?? 0,
+ value['codePoint'] is int
+ ? value['codePoint']
+ : int.tryParse(value['codePoint'].toString()) ?? 0,
fontFamily: value['fontFamily']?.toString() ?? 'MaterialIcons',
);
}
@@ -1558,7 +1795,9 @@ class SduiParser {
(v['offsetX'] is num) ? (v['offsetX'] as num).toDouble() : 0.0,
(v['offsetY'] is num) ? (v['offsetY'] as num).toDouble() : 0.0,
),
- blurRadius: (v['blurRadius'] is num) ? (v['blurRadius'] as num).toDouble() : 0.0,
+ blurRadius: (v['blurRadius'] is num)
+ ? (v['blurRadius'] as num).toDouble()
+ : 0.0,
);
}
return const Shadow();
@@ -1593,12 +1832,21 @@ class SduiParser {
static Map _toJsonColumn(SduiColumn widget) {
return {
'type': 'column',
- if (widget.mainAxisAlignment != null) 'mainAxisAlignment': widget.mainAxisAlignment.toString().split('.').last,
- if (widget.crossAxisAlignment != null) 'crossAxisAlignment': widget.crossAxisAlignment.toString().split('.').last,
- if (widget.mainAxisSize != null) 'mainAxisSize': widget.mainAxisSize.toString().split('.').last,
- if (widget.textDirection != null) 'textDirection': widget.textDirection.toString().split('.').last,
- if (widget.verticalDirection != null) 'verticalDirection': widget.verticalDirection.toString().split('.').last,
- if (widget.textBaseline != null) 'textBaseline': widget.textBaseline.toString().split('.').last,
+ if (widget.mainAxisAlignment != null)
+ 'mainAxisAlignment':
+ widget.mainAxisAlignment.toString().split('.').last,
+ if (widget.crossAxisAlignment != null)
+ 'crossAxisAlignment':
+ widget.crossAxisAlignment.toString().split('.').last,
+ if (widget.mainAxisSize != null)
+ 'mainAxisSize': widget.mainAxisSize.toString().split('.').last,
+ if (widget.textDirection != null)
+ 'textDirection': widget.textDirection.toString().split('.').last,
+ if (widget.verticalDirection != null)
+ 'verticalDirection':
+ widget.verticalDirection.toString().split('.').last,
+ if (widget.textBaseline != null)
+ 'textBaseline': widget.textBaseline.toString().split('.').last,
'children': widget.children.map(toJson).toList(),
};
}
@@ -1606,12 +1854,21 @@ class SduiParser {
static Map _toJsonRow(SduiRow widget) {
return {
'type': 'row',
- if (widget.mainAxisAlignment != null) 'mainAxisAlignment': widget.mainAxisAlignment.toString().split('.').last,
- if (widget.crossAxisAlignment != null) 'crossAxisAlignment': widget.crossAxisAlignment.toString().split('.').last,
- if (widget.mainAxisSize != null) 'mainAxisSize': widget.mainAxisSize.toString().split('.').last,
- if (widget.textDirection != null) 'textDirection': widget.textDirection.toString().split('.').last,
- if (widget.verticalDirection != null) 'verticalDirection': widget.verticalDirection.toString().split('.').last,
- if (widget.textBaseline != null) 'textBaseline': widget.textBaseline.toString().split('.').last,
+ if (widget.mainAxisAlignment != null)
+ 'mainAxisAlignment':
+ widget.mainAxisAlignment.toString().split('.').last,
+ if (widget.crossAxisAlignment != null)
+ 'crossAxisAlignment':
+ widget.crossAxisAlignment.toString().split('.').last,
+ if (widget.mainAxisSize != null)
+ 'mainAxisSize': widget.mainAxisSize.toString().split('.').last,
+ if (widget.textDirection != null)
+ 'textDirection': widget.textDirection.toString().split('.').last,
+ if (widget.verticalDirection != null)
+ 'verticalDirection':
+ widget.verticalDirection.toString().split('.').last,
+ if (widget.textBaseline != null)
+ 'textBaseline': widget.textBaseline.toString().split('.').last,
'children': widget.children.map(toJson).toList(),
};
}
@@ -1621,29 +1878,36 @@ class SduiParser {
'type': 'text',
'text': widget.text,
if (widget.style != null) 'style': _toJsonTextStyle(widget.style!),
- if (widget.textAlign != null) 'textAlign': widget.textAlign.toString().split('.').last,
- if (widget.overflow != null) 'overflow': widget.overflow.toString().split('.').last,
+ if (widget.textAlign != null)
+ 'textAlign': widget.textAlign.toString().split('.').last,
+ if (widget.overflow != null)
+ 'overflow': widget.overflow.toString().split('.').last,
if (widget.maxLines != null) 'maxLines': widget.maxLines,
if (widget.softWrap != null) 'softWrap': widget.softWrap,
if (widget.letterSpacing != null) 'letterSpacing': widget.letterSpacing,
if (widget.wordSpacing != null) 'wordSpacing': widget.wordSpacing,
if (widget.height != null) 'height': widget.height,
if (widget.fontFamily != null) 'fontFamily': widget.fontFamily,
- if (widget.textDirection != null) 'textDirection': widget.textDirection.toString().split('.').last,
+ if (widget.textDirection != null)
+ 'textDirection': widget.textDirection.toString().split('.').last,
};
}
static Map _toJsonTextStyle(TextStyle style) {
return {
- if (style.color != null) 'color': '#${style.color!.value.toRadixString(16).padLeft(8, '0')}',
+ if (style.color != null)
+ 'color': '#${style.color!.value.toRadixString(16).padLeft(8, '0')}',
if (style.fontSize != null) 'fontSize': style.fontSize,
- if (style.fontWeight != null) 'fontWeight': style.fontWeight.toString().split('.').last,
- if (style.decoration != null) 'decoration': style.decoration.toString().split('.').last,
+ if (style.fontWeight != null)
+ 'fontWeight': style.fontWeight.toString().split('.').last,
+ if (style.decoration != null)
+ 'decoration': style.decoration.toString().split('.').last,
if (style.letterSpacing != null) 'letterSpacing': style.letterSpacing,
if (style.wordSpacing != null) 'wordSpacing': style.wordSpacing,
if (style.height != null) 'height': style.height,
if (style.fontFamily != null) 'fontFamily': style.fontFamily,
- if (style.fontStyle != null) 'fontStyle': style.fontStyle.toString().split('.').last,
+ if (style.fontStyle != null)
+ 'fontStyle': style.fontStyle.toString().split('.').last,
};
}
@@ -1655,13 +1919,20 @@ class SduiParser {
if (widget.height != null) 'height': widget.height,
if (widget.fit != null) 'fit': widget.fit.toString().split('.').last,
if (widget.alignment != null) 'alignment': widget.alignment.toString(),
- if (widget.repeat != null) 'repeat': widget.repeat.toString().split('.').last,
- if (widget.color != null) 'color': '#${widget.color!.value.toRadixString(16).padLeft(8, '0')}',
- if (widget.colorBlendMode != null) 'colorBlendMode': widget.colorBlendMode.toString().split('.').last,
- if (widget.centerSlice != null) 'centerSlice': widget.centerSlice.toString(),
- if (widget.matchTextDirection != null) 'matchTextDirection': widget.matchTextDirection,
- if (widget.gaplessPlayback != null) 'gaplessPlayback': widget.gaplessPlayback,
- if (widget.filterQuality != null) 'filterQuality': widget.filterQuality.toString().split('.').last,
+ if (widget.repeat != null)
+ 'repeat': widget.repeat.toString().split('.').last,
+ if (widget.color != null)
+ 'color': '#${widget.color!.value.toRadixString(16).padLeft(8, '0')}',
+ if (widget.colorBlendMode != null)
+ 'colorBlendMode': widget.colorBlendMode.toString().split('.').last,
+ if (widget.centerSlice != null)
+ 'centerSlice': widget.centerSlice.toString(),
+ if (widget.matchTextDirection != null)
+ 'matchTextDirection': widget.matchTextDirection,
+ if (widget.gaplessPlayback != null)
+ 'gaplessPlayback': widget.gaplessPlayback,
+ if (widget.filterQuality != null)
+ 'filterQuality': widget.filterQuality.toString().split('.').last,
if (widget.cacheWidth != null) 'cacheWidth': widget.cacheWidth,
if (widget.cacheHeight != null) 'cacheHeight': widget.cacheHeight,
if (widget.scale != null) 'scale': widget.scale,
@@ -1684,15 +1955,20 @@ class SduiParser {
if (widget.child != null) 'child': toJson(widget.child!),
if (widget.padding != null) 'padding': _toJsonEdgeInsets(widget.padding!),
if (widget.margin != null) 'margin': _toJsonEdgeInsets(widget.margin!),
- if (widget.decoration != null) 'decoration': _toJsonBoxDecoration(widget.decoration!),
+ if (widget.decoration != null)
+ 'decoration': _toJsonBoxDecoration(widget.decoration!),
if (widget.width != null) 'width': widget.width,
if (widget.height != null) 'height': widget.height,
- if (widget.color != null) 'color': '#${widget.color!.value.toRadixString(16).padLeft(8, '0')}',
+ if (widget.color != null)
+ 'color': '#${widget.color!.value.toRadixString(16).padLeft(8, '0')}',
if (widget.alignment != null) 'alignment': widget.alignment.toString(),
- if (widget.constraints != null) 'constraints': _toJsonBoxConstraints(widget.constraints!),
+ if (widget.constraints != null)
+ 'constraints': _toJsonBoxConstraints(widget.constraints!),
if (widget.transform != null) 'transform': widget.transform.toString(),
- if (widget.transformAlignment != null) 'transformAlignment': widget.transformAlignment.toString(),
- if (widget.clipBehavior != null) 'clipBehavior': widget.clipBehavior.toString().split('.').last,
+ if (widget.transformAlignment != null)
+ 'transformAlignment': widget.transformAlignment.toString(),
+ if (widget.clipBehavior != null)
+ 'clipBehavior': widget.clipBehavior.toString().split('.').last,
};
}
@@ -1701,21 +1977,35 @@ class SduiParser {
'type': 'scaffold',
if (widget.appBar != null) 'appBar': toJson(widget.appBar!),
if (widget.body != null) 'body': toJson(widget.body!),
- if (widget.floatingActionButton != null) 'floatingActionButton': toJson(widget.floatingActionButton!),
- if (widget.bottomNavigationBar != null) 'bottomNavigationBar': toJson(widget.bottomNavigationBar!),
+ if (widget.floatingActionButton != null)
+ 'floatingActionButton': toJson(widget.floatingActionButton!),
+ if (widget.bottomNavigationBar != null)
+ 'bottomNavigationBar': toJson(widget.bottomNavigationBar!),
if (widget.drawer != null) 'drawer': toJson(widget.drawer!),
if (widget.endDrawer != null) 'endDrawer': toJson(widget.endDrawer!),
- if (widget.bottomSheet != null) 'bottomSheet': toJson(widget.bottomSheet!),
- if (widget.backgroundColor != null) 'backgroundColor': '#${widget.backgroundColor!.value.toRadixString(16).padLeft(8, '0')}',
- if (widget.resizeToAvoidBottomInset != null) 'resizeToAvoidBottomInset': widget.resizeToAvoidBottomInset,
+ if (widget.bottomSheet != null)
+ 'bottomSheet': toJson(widget.bottomSheet!),
+ if (widget.backgroundColor != null)
+ 'backgroundColor':
+ '#${widget.backgroundColor!.value.toRadixString(16).padLeft(8, '0')}',
+ if (widget.resizeToAvoidBottomInset != null)
+ 'resizeToAvoidBottomInset': widget.resizeToAvoidBottomInset,
if (widget.primary != null) 'primary': widget.primary,
- if (widget.floatingActionButtonLocation != null) 'floatingActionButtonLocation': widget.floatingActionButtonLocation.toString().split('.').last,
+ if (widget.floatingActionButtonLocation != null)
+ 'floatingActionButtonLocation':
+ widget.floatingActionButtonLocation.toString().split('.').last,
if (widget.extendBody != null) 'extendBody': widget.extendBody,
- if (widget.extendBodyBehindAppBar != null) 'extendBodyBehindAppBar': widget.extendBodyBehindAppBar,
- if (widget.drawerScrimColor != null) 'drawerScrimColor': '#${widget.drawerScrimColor!.value.toRadixString(16).padLeft(8, '0')}',
- if (widget.drawerEdgeDragWidth != null) 'drawerEdgeDragWidth': widget.drawerEdgeDragWidth,
- if (widget.drawerEnableOpenDragGesture != null) 'drawerEnableOpenDragGesture': widget.drawerEnableOpenDragGesture,
- if (widget.endDrawerEnableOpenDragGesture != null) 'endDrawerEnableOpenDragGesture': widget.endDrawerEnableOpenDragGesture,
+ if (widget.extendBodyBehindAppBar != null)
+ 'extendBodyBehindAppBar': widget.extendBodyBehindAppBar,
+ if (widget.drawerScrimColor != null)
+ 'drawerScrimColor':
+ '#${widget.drawerScrimColor!.value.toRadixString(16).padLeft(8, '0')}',
+ if (widget.drawerEdgeDragWidth != null)
+ 'drawerEdgeDragWidth': widget.drawerEdgeDragWidth,
+ if (widget.drawerEnableOpenDragGesture != null)
+ 'drawerEnableOpenDragGesture': widget.drawerEnableOpenDragGesture,
+ if (widget.endDrawerEnableOpenDragGesture != null)
+ 'endDrawerEnableOpenDragGesture': widget.endDrawerEnableOpenDragGesture,
};
}
@@ -1731,17 +2021,23 @@ class SduiParser {
'type': 'icon',
if (widget.icon != null) 'icon': widget.icon!.codePoint,
if (widget.size != null) 'size': widget.size,
- if (widget.color != null) 'color': '#${widget.color!.value.toRadixString(16).padLeft(8, '0')}',
+ if (widget.color != null)
+ 'color': '#${widget.color!.value.toRadixString(16).padLeft(8, '0')}',
if (widget.semanticLabel != null) 'semanticLabel': widget.semanticLabel,
- if (widget.textDirection != null) 'textDirection': widget.textDirection.toString().split('.').last,
+ if (widget.textDirection != null)
+ 'textDirection': widget.textDirection.toString().split('.').last,
if (widget.opacity != null) 'opacity': widget.opacity,
- if (widget.applyTextScaling != null) 'applyTextScaling': widget.applyTextScaling,
- if (widget.shadows != null) 'shadows': widget.shadows!.map((s) => s.toString()).toList(),
+ if (widget.applyTextScaling != null)
+ 'applyTextScaling': widget.applyTextScaling,
+ if (widget.shadows != null)
+ 'shadows': widget.shadows!.map((s) => s.toString()).toList(),
};
}
static Map _toJsonEdgeInsets(EdgeInsets edge) {
- if (edge.left == edge.right && edge.left == edge.top && edge.left == edge.bottom) {
+ if (edge.left == edge.right &&
+ edge.left == edge.top &&
+ edge.left == edge.bottom) {
return {'all': edge.left};
}
return {
@@ -1754,13 +2050,17 @@ class SduiParser {
static Map _toJsonBoxDecoration(BoxDecoration decoration) {
return {
- if (decoration.color != null) 'color': '#${decoration.color!.value.toRadixString(16).padLeft(8, '0')}',
- if (decoration.borderRadius != null) 'borderRadius': decoration.borderRadius.toString(),
+ if (decoration.color != null)
+ 'color':
+ '#${decoration.color!.value.toRadixString(16).padLeft(8, '0')}',
+ if (decoration.borderRadius != null)
+ 'borderRadius': decoration.borderRadius.toString(),
// Add more as needed
};
}
- static Map _toJsonBoxConstraints(BoxConstraints constraints) {
+ static Map _toJsonBoxConstraints(
+ BoxConstraints constraints) {
return {
'minWidth': constraints.minWidth,
'maxWidth': constraints.maxWidth,
@@ -1769,7 +2069,8 @@ class SduiParser {
};
}
- static MainAxisAlignmentProto _mainAxisAlignmentToProto(MainAxisAlignment value) {
+ static MainAxisAlignmentProto _mainAxisAlignmentToProto(
+ MainAxisAlignment value) {
switch (value) {
case MainAxisAlignment.start:
return MainAxisAlignmentProto.MAIN_AXIS_START;
@@ -1783,12 +2084,11 @@ class SduiParser {
return MainAxisAlignmentProto.SPACE_AROUND;
case MainAxisAlignment.spaceEvenly:
return MainAxisAlignmentProto.SPACE_EVENLY;
- default:
- return MainAxisAlignmentProto.MAIN_AXIS_START;
}
}
- static CrossAxisAlignmentProto _crossAxisAlignmentToProto(CrossAxisAlignment value) {
+ static CrossAxisAlignmentProto _crossAxisAlignmentToProto(
+ CrossAxisAlignment value) {
switch (value) {
case CrossAxisAlignment.start:
return CrossAxisAlignmentProto.CROSS_AXIS_START;
@@ -1800,8 +2100,6 @@ class SduiParser {
return CrossAxisAlignmentProto.STRETCH;
case CrossAxisAlignment.baseline:
return CrossAxisAlignmentProto.BASELINE;
- default:
- return CrossAxisAlignmentProto.CROSS_AXIS_CENTER;
}
}
@@ -1811,8 +2109,6 @@ class SduiParser {
return MainAxisSizeProto.MIN;
case MainAxisSize.max:
return MainAxisSizeProto.MAX;
- default:
- return MainAxisSizeProto.MAX;
}
}
@@ -1822,19 +2118,16 @@ class SduiParser {
return TextDirectionProto.LTR;
case TextDirection.rtl:
return TextDirectionProto.RTL;
- default:
- return TextDirectionProto.LTR;
}
}
- static VerticalDirectionProto _verticalDirectionToProto(VerticalDirection value) {
+ static VerticalDirectionProto _verticalDirectionToProto(
+ VerticalDirection value) {
switch (value) {
case VerticalDirection.up:
return VerticalDirectionProto.UP;
case VerticalDirection.down:
return VerticalDirectionProto.DOWN;
- default:
- return VerticalDirectionProto.DOWN;
}
}
@@ -1844,8 +2137,6 @@ class SduiParser {
return TextBaselineProto.ALPHABETIC;
case TextBaseline.ideographic:
return TextBaselineProto.IDEOGRAPHIC;
- default:
- return TextBaselineProto.ALPHABETIC;
}
}
@@ -1918,10 +2209,12 @@ class SduiParser {
final data = SduiWidgetData()..type = WidgetType.COLUMN;
data.children.addAll(col.children.map((c) => SduiParser.toProto(c)));
if (col.mainAxisAlignment != null) {
- data.mainAxisAlignment = _mainAxisAlignmentToProto(col.mainAxisAlignment!);
+ data.mainAxisAlignment =
+ _mainAxisAlignmentToProto(col.mainAxisAlignment!);
}
if (col.crossAxisAlignment != null) {
- data.crossAxisAlignment = _crossAxisAlignmentToProto(col.crossAxisAlignment!);
+ data.crossAxisAlignment =
+ _crossAxisAlignmentToProto(col.crossAxisAlignment!);
}
if (col.mainAxisSize != null) {
data.mainAxisSize = _mainAxisSizeToProto(col.mainAxisSize!);
@@ -1930,7 +2223,8 @@ class SduiParser {
data.textDirection = _textDirectionToProto(col.textDirection!);
}
if (col.verticalDirection != null) {
- data.verticalDirection = _verticalDirectionToProto(col.verticalDirection!);
+ data.verticalDirection =
+ _verticalDirectionToProto(col.verticalDirection!);
}
if (col.textBaseline != null) {
data.textBaseline = _textBaselineToProto(col.textBaseline!);
@@ -1942,7 +2236,8 @@ class SduiParser {
return SduiColumn(
children: data.children.map((c) => SduiParser.parseProto(c)).toList(),
mainAxisAlignment: _parseProtoMainAxisAlignment(data.mainAxisAlignment),
- crossAxisAlignment: _parseProtoCrossAxisAlignment(data.crossAxisAlignment),
+ crossAxisAlignment:
+ _parseProtoCrossAxisAlignment(data.crossAxisAlignment),
mainAxisSize: _parseProtoMainAxisSize(data.mainAxisSize),
textDirection: _parseProtoTextDirection(data.textDirection),
verticalDirection: _parseProtoVerticalDirection(data.verticalDirection),
@@ -1970,7 +2265,8 @@ class SduiParser {
} else if (widget is SduiIcon) {
return iconToProto(widget);
}
- throw UnimplementedError('toProto not implemented for [38;5;9m${widget.runtimeType}[0m');
+ throw UnimplementedError(
+ 'toProto not implemented for [38;5;9m${widget.runtimeType}[0m');
}
static SduiWidget fromProto(SduiWidgetData data) {
@@ -2002,22 +2298,45 @@ class SduiParser {
static SduiWidgetData rowToProto(SduiRow row) {
final data = SduiWidgetData()..type = WidgetType.ROW;
data.children.addAll(row.children.map((c) => SduiParser.toProto(c)));
- if (row.mainAxisAlignment != null) data.mainAxisAlignment = _mainAxisAlignmentToProto(row.mainAxisAlignment!);
- if (row.crossAxisAlignment != null) data.crossAxisAlignment = _crossAxisAlignmentToProto(row.crossAxisAlignment!);
- if (row.mainAxisSize != null) data.mainAxisSize = _mainAxisSizeToProto(row.mainAxisSize!);
- if (row.textDirection != null) data.textDirection = _textDirectionToProto(row.textDirection!);
- if (row.verticalDirection != null) data.verticalDirection = _verticalDirectionToProto(row.verticalDirection!);
- if (row.textBaseline != null) data.textBaseline = _textBaselineToProto(row.textBaseline!);
+ if (row.mainAxisAlignment != null) {
+ data.mainAxisAlignment =
+ _mainAxisAlignmentToProto(row.mainAxisAlignment!);
+ }
+ if (row.crossAxisAlignment != null) {
+ data.crossAxisAlignment =
+ _crossAxisAlignmentToProto(row.crossAxisAlignment!);
+ }
+ if (row.mainAxisSize != null) {
+ data.mainAxisSize = _mainAxisSizeToProto(row.mainAxisSize!);
+ }
+ if (row.textDirection != null) {
+ data.textDirection = _textDirectionToProto(row.textDirection!);
+ }
+ if (row.verticalDirection != null) {
+ data.verticalDirection =
+ _verticalDirectionToProto(row.verticalDirection!);
+ }
+ if (row.textBaseline != null) {
+ data.textBaseline = _textBaselineToProto(row.textBaseline!);
+ }
return data;
}
static SduiRow rowFromProto(SduiWidgetData data) {
- List children = data.children.map((c) => SduiParser.parseProto(c)).toList();
- MainAxisAlignment mainAxisAlignment = _parseProtoMainAxisAlignment(data.mainAxisAlignment) ?? MainAxisAlignment.start;
- CrossAxisAlignment crossAxisAlignment = _parseProtoCrossAxisAlignment(data.crossAxisAlignment) ?? CrossAxisAlignment.center;
- MainAxisSize mainAxisSize = _parseProtoMainAxisSize(data.mainAxisSize) ?? MainAxisSize.max;
+ List children =
+ data.children.map((c) => SduiParser.parseProto(c)).toList();
+ MainAxisAlignment mainAxisAlignment =
+ _parseProtoMainAxisAlignment(data.mainAxisAlignment) ??
+ MainAxisAlignment.start;
+ CrossAxisAlignment crossAxisAlignment =
+ _parseProtoCrossAxisAlignment(data.crossAxisAlignment) ??
+ CrossAxisAlignment.center;
+ MainAxisSize mainAxisSize =
+ _parseProtoMainAxisSize(data.mainAxisSize) ?? MainAxisSize.max;
TextDirection? textDirection = _parseProtoTextDirection(data.textDirection);
- VerticalDirection verticalDirection = _parseProtoVerticalDirection(data.verticalDirection) ?? VerticalDirection.down;
+ VerticalDirection verticalDirection =
+ _parseProtoVerticalDirection(data.verticalDirection) ??
+ VerticalDirection.down;
TextBaseline? textBaseline = _parseProtoTextBaseline(data.textBaseline);
return SduiRow(
children: children,
@@ -2035,26 +2354,37 @@ class SduiParser {
final data = SduiWidgetData()..type = WidgetType.TEXT;
data.stringAttributes['text'] = text.text;
if (text.style != null) data.textStyle = _textStyleToProto(text.style!);
- if (text.textAlign != null) data.textAlign = _textAlignToProto(text.textAlign!);
- if (text.overflow != null) data.overflow = _textOverflowToProto(text.overflow!);
+ if (text.textAlign != null) {
+ data.textAlign = _textAlignToProto(text.textAlign!);
+ }
+ if (text.overflow != null) {
+ data.overflow = _textOverflowToProto(text.overflow!);
+ }
if (text.maxLines != null) data.maxLines = text.maxLines!;
if (text.softWrap != null) data.softWrap = text.softWrap!;
if (text.letterSpacing != null) data.letterSpacing = text.letterSpacing!;
if (text.wordSpacing != null) data.wordSpacing = text.wordSpacing!;
if (text.height != null) data.height = text.height!;
if (text.fontFamily != null) data.fontFamily = text.fontFamily!;
- if (text.textDirection != null) data.textDirection = _textDirectionToProto(text.textDirection!);
+ if (text.textDirection != null) {
+ data.textDirection = _textDirectionToProto(text.textDirection!);
+ }
// Individual style overrides
- if (text.decoration != null) data.textStyle.decoration = _textDecorationToProto(text.decoration!);
+ if (text.decoration != null) {
+ data.textStyle.decoration = _textDecorationToProto(text.decoration!);
+ }
if (text.fontSize != null) data.textStyle.fontSize = text.fontSize!;
- if (text.fontWeight != null) data.textStyle.fontWeight = text.fontWeight.toString().split('.').last;
+ if (text.fontWeight != null) {
+ data.textStyle.fontWeight = text.fontWeight.toString().split('.').last;
+ }
if (text.color != null) data.textStyle.color = _colorToProto(text.color!);
return data;
}
static SduiText textFromProto(SduiWidgetData data) {
String text = data.stringAttributes['text'] ?? '';
- TextStyle? style = data.hasTextStyle() ? _parseProtoTextStyle(data.textStyle) : null;
+ TextStyle? style =
+ data.hasTextStyle() ? _parseProtoTextStyle(data.textStyle) : null;
TextAlign? textAlign = _parseProtoTextAlign(data.textAlign);
TextOverflow? overflow = _parseProtoTextOverflow(data.overflow);
int? maxLines = data.hasMaxLines() ? data.maxLines : null;
@@ -2065,10 +2395,20 @@ class SduiParser {
String? fontFamily = data.hasFontFamily() ? data.fontFamily : null;
TextDirection? textDirection = _parseProtoTextDirection(data.textDirection);
// Individual style overrides
- TextDecoration? decoration = data.hasTextStyle() && data.textStyle.hasDecoration() ? _parseProtoTextDecoration(data.textStyle.decoration) : null;
- double? fontSize = data.hasTextStyle() && data.textStyle.hasFontSize() ? data.textStyle.fontSize : null;
- FontWeight? fontWeight = data.hasTextStyle() && data.textStyle.fontWeight.isNotEmpty ? _parseProtoFontWeight(data.textStyle.fontWeight) : null;
- Color? color = data.hasTextStyle() && data.textStyle.hasColor() ? _parseProtoColor(data.textStyle.color) : null;
+ TextDecoration? decoration =
+ data.hasTextStyle() && data.textStyle.hasDecoration()
+ ? _parseProtoTextDecoration(data.textStyle.decoration)
+ : null;
+ double? fontSize = data.hasTextStyle() && data.textStyle.hasFontSize()
+ ? data.textStyle.fontSize
+ : null;
+ FontWeight? fontWeight =
+ data.hasTextStyle() && data.textStyle.fontWeight.isNotEmpty
+ ? _parseProtoFontWeight(data.textStyle.fontWeight)
+ : null;
+ Color? color = data.hasTextStyle() && data.textStyle.hasColor()
+ ? _parseProtoColor(data.textStyle.color)
+ : null;
return SduiText(
text,
style: style,
@@ -2094,15 +2434,29 @@ class SduiParser {
data.stringAttributes['src'] = image.src;
if (image.width != null) data.doubleAttributes['width'] = image.width!;
if (image.height != null) data.doubleAttributes['height'] = image.height!;
- if (image.fit != null) data.stringAttributes['fit'] = image.fit.toString().split('.').last;
- if (image.alignment != null) data.alignment = _alignmentToProto(image.alignment!);
+ if (image.fit != null) {
+ data.stringAttributes['fit'] = image.fit.toString().split('.').last;
+ }
+ if (image.alignment != null) {
+ data.alignment = _alignmentToProto(image.alignment!);
+ }
if (image.repeat != null) data.repeat = _imageRepeatToProto(image.repeat!);
if (image.color != null) data.color = _colorToProto(image.color!);
- if (image.colorBlendMode != null) data.colorBlendMode = _blendModeToProto(image.colorBlendMode!);
- if (image.centerSlice != null) data.centerSlice = _rectToProto(image.centerSlice!);
- if (image.matchTextDirection != null) data.matchTextDirection = image.matchTextDirection!;
- if (image.gaplessPlayback != null) data.gaplessPlayback = image.gaplessPlayback!;
- if (image.filterQuality != null) data.filterQuality = _filterQualityToProto(image.filterQuality!);
+ if (image.colorBlendMode != null) {
+ data.colorBlendMode = _blendModeToProto(image.colorBlendMode!);
+ }
+ if (image.centerSlice != null) {
+ data.centerSlice = _rectToProto(image.centerSlice!);
+ }
+ if (image.matchTextDirection != null) {
+ data.matchTextDirection = image.matchTextDirection!;
+ }
+ if (image.gaplessPlayback != null) {
+ data.gaplessPlayback = image.gaplessPlayback!;
+ }
+ if (image.filterQuality != null) {
+ data.filterQuality = _filterQualityToProto(image.filterQuality!);
+ }
if (image.cacheWidth != null) data.cacheWidth = image.cacheWidth!;
if (image.cacheHeight != null) data.cacheHeight = image.cacheHeight!;
if (image.scale != null) data.scale = image.scale!;
@@ -2116,14 +2470,20 @@ class SduiParser {
double? width = data.doubleAttributes['width'];
double? height = data.doubleAttributes['height'];
BoxFit? fit = _parseProtoBoxFit(data.stringAttributes['fit']);
- Alignment alignment = _parseProtoAlignment(data.alignment) ?? Alignment.center;
- ImageRepeat repeat = _parseProtoImageRepeat(data.repeat) ?? ImageRepeat.noRepeat;
+ Alignment alignment =
+ _parseProtoAlignment(data.alignment) ?? Alignment.center;
+ ImageRepeat repeat =
+ _parseProtoImageRepeat(data.repeat) ?? ImageRepeat.noRepeat;
Color? color = data.hasColor() ? _parseProtoColor(data.color) : null;
BlendMode? colorBlendMode = _parseProtoBlendMode(data.colorBlendMode);
- Rect? centerSlice = data.hasCenterSlice() ? _parseProtoRect(data.centerSlice) : null;
- bool matchTextDirection = data.hasMatchTextDirection() ? data.matchTextDirection : false;
- bool gaplessPlayback = data.hasGaplessPlayback() ? data.gaplessPlayback : false;
- FilterQuality filterQuality = _parseProtoFilterQuality(data.filterQuality) ?? FilterQuality.low;
+ Rect? centerSlice =
+ data.hasCenterSlice() ? _parseProtoRect(data.centerSlice) : null;
+ bool matchTextDirection =
+ data.hasMatchTextDirection() ? data.matchTextDirection : false;
+ bool gaplessPlayback =
+ data.hasGaplessPlayback() ? data.gaplessPlayback : false;
+ FilterQuality filterQuality =
+ _parseProtoFilterQuality(data.filterQuality) ?? FilterQuality.low;
int? cacheWidth = data.hasCacheWidth() ? data.cacheWidth : null;
int? cacheHeight = data.hasCacheHeight() ? data.cacheHeight : null;
double scale = data.hasScale() ? data.scale : 1.0;
@@ -2259,7 +2619,8 @@ class SduiParser {
static SduiSizedBox sizedBoxFromProto(SduiWidgetData data) {
double? width = data.doubleAttributes['width'];
double? height = data.doubleAttributes['height'];
- SduiWidget? child = data.hasChild() ? SduiParser.parseProto(data.child) : null;
+ SduiWidget? child =
+ data.hasChild() ? SduiParser.parseProto(data.child) : null;
return SduiSizedBox(width: width, height: height, child: child);
}
@@ -2269,33 +2630,57 @@ class SduiParser {
if (c.child != null) data.child = toProto(c.child!);
if (c.padding != null) data.padding = _edgeInsetsToProto(c.padding!);
if (c.margin != null) data.margin = _edgeInsetsToProto(c.margin!);
- if (c.decoration != null) data.boxDecoration = _boxDecorationToProto(c.decoration!);
+ if (c.decoration != null) {
+ data.boxDecoration = _boxDecorationToProto(c.decoration!);
+ }
if (c.width != null) data.doubleAttributes['width'] = c.width!;
if (c.height != null) data.doubleAttributes['height'] = c.height!;
// Only set color if decoration is null
- if (c.decoration == null && c.color != null) data.color = _colorToProto(c.color!);
+ if (c.decoration == null && c.color != null) {
+ data.color = _colorToProto(c.color!);
+ }
if (c.alignment != null) data.alignment = _alignmentToProto(c.alignment!);
- if (c.constraints != null) data.constraints = _boxConstraintsToProto(c.constraints!);
+ if (c.constraints != null) {
+ data.constraints = _boxConstraintsToProto(c.constraints!);
+ }
if (c.transform != null) data.transform = _matrix4ToProto(c.transform!);
- if (c.transformAlignment != null) data.transformAlignment = _alignmentGeometryToProto(c.transformAlignment!);
- if (c.clipBehavior != null && c.clipBehavior != Clip.none) data.clipBehavior = _clipToProto(c.clipBehavior!);
+ if (c.transformAlignment != null) {
+ data.transformAlignment =
+ _alignmentGeometryToProto(c.transformAlignment!);
+ }
+ if (c.clipBehavior != null && c.clipBehavior != Clip.none) {
+ data.clipBehavior = _clipToProto(c.clipBehavior!);
+ }
return data;
}
static SduiContainer containerFromProto(SduiWidgetData data) {
- SduiWidget? child = data.hasChild() ? SduiParser.parseProto(data.child) : null;
- EdgeInsets? padding = data.hasPadding() ? _parseProtoEdgeInsets(data.padding) : null;
- EdgeInsets? margin = data.hasMargin() ? _parseProtoEdgeInsets(data.margin) : null;
- BoxDecoration? decoration = data.hasBoxDecoration() ? _parseProtoBoxDecoration(data.boxDecoration) : null;
+ SduiWidget? child =
+ data.hasChild() ? SduiParser.parseProto(data.child) : null;
+ EdgeInsets? padding =
+ data.hasPadding() ? _parseProtoEdgeInsets(data.padding) : null;
+ EdgeInsets? margin =
+ data.hasMargin() ? _parseProtoEdgeInsets(data.margin) : null;
+ BoxDecoration? decoration = data.hasBoxDecoration()
+ ? _parseProtoBoxDecoration(data.boxDecoration)
+ : null;
double? width = data.doubleAttributes['width'];
double? height = data.doubleAttributes['height'];
// Only use color if decoration is null
- Color? color = (decoration == null && data.hasColor()) ? _parseProtoColor(data.color) : null;
+ Color? color = (decoration == null && data.hasColor())
+ ? _parseProtoColor(data.color)
+ : null;
Alignment? alignment = _parseProtoAlignment(data.alignment);
- BoxConstraints? constraints = data.hasConstraints() ? _parseProtoBoxConstraints(data.constraints) : null;
- Matrix4? transform = data.hasTransform() ? _parseProtoTransform(data.transform) : null;
- AlignmentGeometry? transformAlignment = data.hasTransformAlignment() ? _parseProtoAlignmentGeometry(data.transformAlignment) : null;
- Clip? clipBehavior = data.hasClipBehavior() ? _parseProtoClip(data.clipBehavior) : Clip.none;
+ BoxConstraints? constraints = data.hasConstraints()
+ ? _parseProtoBoxConstraints(data.constraints)
+ : null;
+ Matrix4? transform =
+ data.hasTransform() ? _parseProtoTransform(data.transform) : null;
+ AlignmentGeometry? transformAlignment = data.hasTransformAlignment()
+ ? _parseProtoAlignmentGeometry(data.transformAlignment)
+ : null;
+ Clip? clipBehavior =
+ data.hasClipBehavior() ? _parseProtoClip(data.clipBehavior) : Clip.none;
return SduiContainer(
child: child,
padding: padding,
@@ -2314,7 +2699,9 @@ class SduiParser {
static EdgeInsetsData _edgeInsetsToProto(EdgeInsets edge) {
final data = EdgeInsetsData();
- if (edge.left == edge.right && edge.left == edge.top && edge.left == edge.bottom) {
+ if (edge.left == edge.right &&
+ edge.left == edge.top &&
+ edge.left == edge.bottom) {
data.all = edge.left;
} else {
data.left = edge.left;
@@ -2328,8 +2715,10 @@ class SduiParser {
static BoxDecorationData _boxDecorationToProto(BoxDecoration decoration) {
final data = BoxDecorationData();
if (decoration.color != null) data.color = _colorToProto(decoration.color!);
- if (decoration.borderRadius != null && decoration.borderRadius is BorderRadius) {
- data.borderRadius = _borderRadiusToProto(decoration.borderRadius as BorderRadius);
+ if (decoration.borderRadius != null &&
+ decoration.borderRadius is BorderRadius) {
+ data.borderRadius =
+ _borderRadiusToProto(decoration.borderRadius as BorderRadius);
}
// Add more as needed
return data;
@@ -2379,7 +2768,8 @@ class SduiParser {
return _alignmentToProto(alignment);
}
// Fallback: center
- return AlignmentData()..predefined = AlignmentData_PredefinedAlignment.CENTER_ALIGN;
+ return AlignmentData()
+ ..predefined = AlignmentData_PredefinedAlignment.CENTER_ALIGN;
}
static ClipProto _clipToProto(Clip clip) {
@@ -2400,42 +2790,87 @@ class SduiParser {
final data = SduiWidgetData()..type = WidgetType.SCAFFOLD;
if (s.appBar != null) data.appBar = toProto(s.appBar!);
if (s.body != null) data.body = toProto(s.body!);
- if (s.floatingActionButton != null) data.floatingActionButton = toProto(s.floatingActionButton!);
- if (s.bottomNavigationBar != null) data.bottomNavigationBar = toProto(s.bottomNavigationBar!);
+ if (s.floatingActionButton != null) {
+ data.floatingActionButton = toProto(s.floatingActionButton!);
+ }
+ if (s.bottomNavigationBar != null) {
+ data.bottomNavigationBar = toProto(s.bottomNavigationBar!);
+ }
if (s.drawer != null) data.drawer = toProto(s.drawer!);
if (s.endDrawer != null) data.endDrawer = toProto(s.endDrawer!);
if (s.bottomSheet != null) data.bottomSheet = toProto(s.bottomSheet!);
- if (s.backgroundColor != null) data.backgroundColor = _colorToProto(s.backgroundColor!);
- if (s.resizeToAvoidBottomInset != null) data.resizeToAvoidBottomInset = s.resizeToAvoidBottomInset!;
+ if (s.backgroundColor != null) {
+ data.backgroundColor = _colorToProto(s.backgroundColor!);
+ }
+ if (s.resizeToAvoidBottomInset != null) {
+ data.resizeToAvoidBottomInset = s.resizeToAvoidBottomInset!;
+ }
if (s.primary != null) data.primary = s.primary!;
- if (s.floatingActionButtonLocation != null) data.floatingActionButtonLocation = _fabLocationToProto(s.floatingActionButtonLocation!);
+ if (s.floatingActionButtonLocation != null) {
+ data.floatingActionButtonLocation =
+ _fabLocationToProto(s.floatingActionButtonLocation!);
+ }
if (s.extendBody != null) data.extendBody = s.extendBody!;
- if (s.extendBodyBehindAppBar != null) data.extendBodyBehindAppBar = s.extendBodyBehindAppBar!;
- if (s.drawerScrimColor != null) data.drawerScrimColor = _colorToProto(s.drawerScrimColor!);
- if (s.drawerEdgeDragWidth != null) data.drawerEdgeDragWidth = s.drawerEdgeDragWidth!;
- if (s.drawerEnableOpenDragGesture != null) data.drawerEnableOpenDragGesture = s.drawerEnableOpenDragGesture!;
- if (s.endDrawerEnableOpenDragGesture != null) data.endDrawerEnableOpenDragGesture = s.endDrawerEnableOpenDragGesture!;
+ if (s.extendBodyBehindAppBar != null) {
+ data.extendBodyBehindAppBar = s.extendBodyBehindAppBar!;
+ }
+ if (s.drawerScrimColor != null) {
+ data.drawerScrimColor = _colorToProto(s.drawerScrimColor!);
+ }
+ if (s.drawerEdgeDragWidth != null) {
+ data.drawerEdgeDragWidth = s.drawerEdgeDragWidth!;
+ }
+ if (s.drawerEnableOpenDragGesture != null) {
+ data.drawerEnableOpenDragGesture = s.drawerEnableOpenDragGesture!;
+ }
+ if (s.endDrawerEnableOpenDragGesture != null) {
+ data.endDrawerEnableOpenDragGesture = s.endDrawerEnableOpenDragGesture!;
+ }
return data;
}
static SduiScaffold scaffoldFromProto(SduiWidgetData data) {
- SduiWidget? appBar = data.hasAppBar() ? SduiParser.parseProto(data.appBar) : null;
+ SduiWidget? appBar =
+ data.hasAppBar() ? SduiParser.parseProto(data.appBar) : null;
SduiWidget? body = data.hasBody() ? SduiParser.parseProto(data.body) : null;
- SduiWidget? floatingActionButton = data.hasFloatingActionButton() ? SduiParser.parseProto(data.floatingActionButton) : null;
- SduiWidget? bottomNavigationBar = data.hasBottomNavigationBar() ? SduiParser.parseProto(data.bottomNavigationBar) : null;
- SduiWidget? drawer = data.hasDrawer() ? SduiParser.parseProto(data.drawer) : null;
- SduiWidget? endDrawer = data.hasEndDrawer() ? SduiParser.parseProto(data.endDrawer) : null;
- SduiWidget? bottomSheet = data.hasBottomSheet() ? SduiParser.parseProto(data.bottomSheet) : null;
- Color? backgroundColor = data.hasBackgroundColor() ? _parseProtoColor(data.backgroundColor) : null;
- bool? resizeToAvoidBottomInset = data.hasResizeToAvoidBottomInset() ? data.resizeToAvoidBottomInset : null;
+ SduiWidget? floatingActionButton = data.hasFloatingActionButton()
+ ? SduiParser.parseProto(data.floatingActionButton)
+ : null;
+ SduiWidget? bottomNavigationBar = data.hasBottomNavigationBar()
+ ? SduiParser.parseProto(data.bottomNavigationBar)
+ : null;
+ SduiWidget? drawer =
+ data.hasDrawer() ? SduiParser.parseProto(data.drawer) : null;
+ SduiWidget? endDrawer =
+ data.hasEndDrawer() ? SduiParser.parseProto(data.endDrawer) : null;
+ SduiWidget? bottomSheet =
+ data.hasBottomSheet() ? SduiParser.parseProto(data.bottomSheet) : null;
+ Color? backgroundColor = data.hasBackgroundColor()
+ ? _parseProtoColor(data.backgroundColor)
+ : null;
+ bool? resizeToAvoidBottomInset = data.hasResizeToAvoidBottomInset()
+ ? data.resizeToAvoidBottomInset
+ : null;
bool primary = data.hasPrimary() ? data.primary : true;
- FloatingActionButtonLocation? floatingActionButtonLocation = data.hasFloatingActionButtonLocation() ? _parseProtoFabLocation(data.floatingActionButtonLocation) : null;
+ FloatingActionButtonLocation? floatingActionButtonLocation =
+ data.hasFloatingActionButtonLocation()
+ ? _parseProtoFabLocation(data.floatingActionButtonLocation)
+ : null;
bool extendBody = data.hasExtendBody() ? data.extendBody : false;
- bool extendBodyBehindAppBar = data.hasExtendBodyBehindAppBar() ? data.extendBodyBehindAppBar : false;
- Color? drawerScrimColor = data.hasDrawerScrimColor() ? _parseProtoColor(data.drawerScrimColor) : null;
- double? drawerEdgeDragWidth = data.hasDrawerEdgeDragWidth() ? data.drawerEdgeDragWidth : null;
- bool drawerEnableOpenDragGesture = data.hasDrawerEnableOpenDragGesture() ? data.drawerEnableOpenDragGesture : true;
- bool endDrawerEnableOpenDragGesture = data.hasEndDrawerEnableOpenDragGesture() ? data.endDrawerEnableOpenDragGesture : true;
+ bool extendBodyBehindAppBar =
+ data.hasExtendBodyBehindAppBar() ? data.extendBodyBehindAppBar : false;
+ Color? drawerScrimColor = data.hasDrawerScrimColor()
+ ? _parseProtoColor(data.drawerScrimColor)
+ : null;
+ double? drawerEdgeDragWidth =
+ data.hasDrawerEdgeDragWidth() ? data.drawerEdgeDragWidth : null;
+ bool drawerEnableOpenDragGesture = data.hasDrawerEnableOpenDragGesture()
+ ? data.drawerEnableOpenDragGesture
+ : true;
+ bool endDrawerEnableOpenDragGesture =
+ data.hasEndDrawerEnableOpenDragGesture()
+ ? data.endDrawerEnableOpenDragGesture
+ : true;
return SduiScaffold(
appBar: appBar,
body: body,
@@ -2457,20 +2892,45 @@ class SduiParser {
);
}
- static FloatingActionButtonLocationProto _fabLocationToProto(FloatingActionButtonLocation loc) {
+ static FloatingActionButtonLocationProto _fabLocationToProto(
+ FloatingActionButtonLocation loc) {
// Use the same mapping as _parseProtoFabLocation, but reversed
- if (loc == FloatingActionButtonLocation.startTop) return FloatingActionButtonLocationProto.FAB_START_TOP;
- if (loc == FloatingActionButtonLocation.startFloat) return FloatingActionButtonLocationProto.FAB_START_FLOAT;
- if (loc == FloatingActionButtonLocation.centerTop) return FloatingActionButtonLocationProto.FAB_CENTER_TOP;
- if (loc == FloatingActionButtonLocation.centerFloat) return FloatingActionButtonLocationProto.FAB_CENTER_FLOAT;
- if (loc == FloatingActionButtonLocation.endTop) return FloatingActionButtonLocationProto.FAB_END_TOP;
- if (loc == FloatingActionButtonLocation.endFloat) return FloatingActionButtonLocationProto.FAB_END_FLOAT;
- if (loc == FloatingActionButtonLocation.miniCenterTop) return FloatingActionButtonLocationProto.FAB_MINI_CENTER_TOP;
- if (loc == FloatingActionButtonLocation.miniCenterFloat) return FloatingActionButtonLocationProto.FAB_MINI_CENTER_FLOAT;
- if (loc == FloatingActionButtonLocation.miniStartTop) return FloatingActionButtonLocationProto.FAB_MINI_START_TOP;
- if (loc == FloatingActionButtonLocation.miniStartFloat) return FloatingActionButtonLocationProto.FAB_MINI_START_FLOAT;
- if (loc == FloatingActionButtonLocation.miniEndTop) return FloatingActionButtonLocationProto.FAB_MINI_END_TOP;
- if (loc == FloatingActionButtonLocation.miniEndFloat) return FloatingActionButtonLocationProto.FAB_MINI_END_FLOAT;
+ if (loc == FloatingActionButtonLocation.startTop) {
+ return FloatingActionButtonLocationProto.FAB_START_TOP;
+ }
+ if (loc == FloatingActionButtonLocation.startFloat) {
+ return FloatingActionButtonLocationProto.FAB_START_FLOAT;
+ }
+ if (loc == FloatingActionButtonLocation.centerTop) {
+ return FloatingActionButtonLocationProto.FAB_CENTER_TOP;
+ }
+ if (loc == FloatingActionButtonLocation.centerFloat) {
+ return FloatingActionButtonLocationProto.FAB_CENTER_FLOAT;
+ }
+ if (loc == FloatingActionButtonLocation.endTop) {
+ return FloatingActionButtonLocationProto.FAB_END_TOP;
+ }
+ if (loc == FloatingActionButtonLocation.endFloat) {
+ return FloatingActionButtonLocationProto.FAB_END_FLOAT;
+ }
+ if (loc == FloatingActionButtonLocation.miniCenterTop) {
+ return FloatingActionButtonLocationProto.FAB_MINI_CENTER_TOP;
+ }
+ if (loc == FloatingActionButtonLocation.miniCenterFloat) {
+ return FloatingActionButtonLocationProto.FAB_MINI_CENTER_FLOAT;
+ }
+ if (loc == FloatingActionButtonLocation.miniStartTop) {
+ return FloatingActionButtonLocationProto.FAB_MINI_START_TOP;
+ }
+ if (loc == FloatingActionButtonLocation.miniStartFloat) {
+ return FloatingActionButtonLocationProto.FAB_MINI_START_FLOAT;
+ }
+ if (loc == FloatingActionButtonLocation.miniEndTop) {
+ return FloatingActionButtonLocationProto.FAB_MINI_END_TOP;
+ }
+ if (loc == FloatingActionButtonLocation.miniEndFloat) {
+ return FloatingActionButtonLocationProto.FAB_MINI_END_FLOAT;
+ }
return FloatingActionButtonLocationProto.FAB_CENTER_FLOAT;
}
@@ -2497,22 +2957,32 @@ class SduiParser {
if (icon.size != null) data.icon.size = icon.size!;
if (icon.color != null) data.icon.color = _colorToProto(icon.color!);
if (icon.semanticLabel != null) data.semanticLabel = icon.semanticLabel!;
- if (icon.textDirection != null) data.textDirection = _textDirectionToProto(icon.textDirection!);
+ if (icon.textDirection != null) {
+ data.textDirection = _textDirectionToProto(icon.textDirection!);
+ }
if (icon.opacity != null) data.opacity = icon.opacity!;
- if (icon.applyTextScaling != null) data.applyTextScaling = icon.applyTextScaling!;
- if (icon.shadows != null) data.shadows.addAll(icon.shadows!.map(_shadowToProto));
+ if (icon.applyTextScaling != null) {
+ data.applyTextScaling = icon.applyTextScaling!;
+ }
+ if (icon.shadows != null) {
+ data.shadows.addAll(icon.shadows!.map(_shadowToProto));
+ }
return data;
}
static SduiIcon iconFromProto(SduiWidgetData data) {
IconData? iconData = data.hasIcon() ? _parseProtoIconData(data.icon) : null;
double? size = data.icon.size;
- Color? color = data.icon.hasColor() ? _parseProtoColor(data.icon.color) : null;
+ Color? color =
+ data.icon.hasColor() ? _parseProtoColor(data.icon.color) : null;
String? semanticLabel = data.hasSemanticLabel() ? data.semanticLabel : null;
TextDirection? textDirection = _parseProtoTextDirection(data.textDirection);
double? opacity = data.hasOpacity() ? data.opacity : null;
- bool? applyTextScaling = data.hasApplyTextScaling() ? data.applyTextScaling : null;
- List? shadows = data.shadows.isNotEmpty ? data.shadows.map((s) => _parseProtoShadow(s)).toList() : null;
+ bool? applyTextScaling =
+ data.hasApplyTextScaling() ? data.applyTextScaling : null;
+ List? shadows = data.shadows.isNotEmpty
+ ? data.shadows.map((s) => _parseProtoShadow(s)).toList()
+ : null;
return SduiIcon(
icon: iconData,
size: size,
@@ -2538,13 +3008,19 @@ class SduiParser {
final data = TextStyleData();
if (style.color != null) data.color = _colorToProto(style.color!);
if (style.fontSize != null) data.fontSize = style.fontSize!;
- if (style.fontWeight != null) data.fontWeight = style.fontWeight.toString().split('.').last;
- if (style.decoration != null) data.decoration = _textDecorationToProto(style.decoration!);
+ if (style.fontWeight != null) {
+ data.fontWeight = style.fontWeight.toString().split('.').last;
+ }
+ if (style.decoration != null) {
+ data.decoration = _textDecorationToProto(style.decoration!);
+ }
if (style.letterSpacing != null) data.letterSpacing = style.letterSpacing!;
if (style.wordSpacing != null) data.wordSpacing = style.wordSpacing!;
if (style.height != null) data.height = style.height!;
if (style.fontFamily != null) data.fontFamily = style.fontFamily!;
- if (style.fontStyle != null) data.fontStyle = _fontStyleToProto(style.fontStyle!);
+ if (style.fontStyle != null) {
+ data.fontStyle = _fontStyleToProto(style.fontStyle!);
+ }
return data;
}
@@ -2562,8 +3038,6 @@ class SduiParser {
return TextAlignProto.TEXT_ALIGN_START;
case TextAlign.end:
return TextAlignProto.TEXT_ALIGN_END;
- default:
- return TextAlignProto.LEFT;
}
}
@@ -2577,24 +3051,30 @@ class SduiParser {
return TextOverflowProto.FADE;
case TextOverflow.visible:
return TextOverflowProto.VISIBLE;
- default:
- return TextOverflowProto.CLIP;
}
}
static ColorData _colorToProto(Color color) {
return ColorData()
- ..alpha = color.alpha
- ..red = color.red
- ..green = color.green
- ..blue = color.blue;
+ ..alpha = ((color.a * 255.0).round() & 0xff)
+ ..red = ((color.r * 255.0).round() & 0xff)
+ ..green = ((color.g * 255.0).round() & 0xff)
+ ..blue = ((color.b * 255.0).round() & 0xff);
}
static TextDecorationProto _textDecorationToProto(TextDecoration decoration) {
- if (decoration == TextDecoration.none) return TextDecorationProto.TEXT_DECORATION_NONE;
- if (decoration == TextDecoration.underline) return TextDecorationProto.UNDERLINE;
- if (decoration == TextDecoration.overline) return TextDecorationProto.OVERLINE;
- if (decoration == TextDecoration.lineThrough) return TextDecorationProto.LINE_THROUGH;
+ if (decoration == TextDecoration.none) {
+ return TextDecorationProto.TEXT_DECORATION_NONE;
+ }
+ if (decoration == TextDecoration.underline) {
+ return TextDecorationProto.UNDERLINE;
+ }
+ if (decoration == TextDecoration.overline) {
+ return TextDecorationProto.OVERLINE;
+ }
+ if (decoration == TextDecoration.lineThrough) {
+ return TextDecorationProto.LINE_THROUGH;
+ }
return TextDecorationProto.TEXT_DECORATION_NONE;
}
@@ -2604,8 +3084,6 @@ class SduiParser {
return FontStyleProto.NORMAL;
case FontStyle.italic:
return FontStyleProto.ITALIC;
- default:
- return FontStyleProto.NORMAL;
}
}
}
diff --git a/lib/src/renderer/sdui_grpc_renderer.dart b/lib/src/renderer/sdui_grpc_renderer.dart
index 385a59a..a088c57 100644
--- a/lib/src/renderer/sdui_grpc_renderer.dart
+++ b/lib/src/renderer/sdui_grpc_renderer.dart
@@ -4,21 +4,47 @@ import 'package:flutter_sdui/src/parser/sdui_proto_parser.dart';
import 'package:flutter_sdui/src/service/sdui_grpc_client.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// A widget that renders a UI from a gRPC server.
+/// A Flutter widget that renders server-driven UI from a gRPC server.
+///
+/// This widget acts as the main entry point for rendering server-driven UI.
+/// It fetches widget definitions from a gRPC server, parses them, and renders
+/// the resulting widget tree in the Flutter app.
+///
+/// The renderer handles loading states, error states, and automatic re-fetching
+/// when the screen ID or client changes.
+///
+/// Example usage:
+/// ```dart
+/// SduiGrpcRenderer(
+/// client: sduiClient,
+/// screenId: 'home',
+/// loadingWidget: CustomLoadingSpinner(),
+/// errorBuilder: (context, error) => ErrorWidget(error),
+/// )
+/// ```
class SduiGrpcRenderer extends StatefulWidget {
- /// The gRPC client to use for fetching UI widgets.
+ /// The gRPC client used to fetch widget data from the server.
final SduiGrpcClient client;
- /// The screen ID to fetch from the server.
+ /// The identifier for the screen/UI to fetch from the server.
+ /// This should correspond to a valid screen ID on the server.
final String screenId;
- /// Optional loading widget to display while fetching the UI.
+ /// Optional widget to display while the UI is being fetched.
+ /// If not provided, a default [CircularProgressIndicator] is shown.
final Widget? loadingWidget;
- /// Optional error widget builder to display if an error occurs.
+ /// Optional builder function to create a custom error widget.
+ ///
+ /// The function receives the [BuildContext] and the error [Object].
+ /// If not provided, a default error text widget is displayed.
final Widget Function(BuildContext, Object)? errorBuilder;
- /// Creates a new SduiGrpcRenderer.
+ /// Creates a new [SduiGrpcRenderer].
+ ///
+ /// The [client] and [screenId] parameters are required.
+ /// The [loadingWidget] and [errorBuilder] parameters are optional
+ /// and provide customization for loading and error states.
const SduiGrpcRenderer({
super.key,
required this.client,
@@ -49,6 +75,7 @@ class _SduiGrpcRendererState extends State {
}
}
+ /// Initiates a request to fetch widget data from the server.
void _fetchWidget() {
_widgetFuture = widget.client.getWidget(widget.screenId);
}
@@ -67,8 +94,7 @@ class _SduiGrpcRendererState extends State {
}
return Center(child: Text('Error: ${snapshot.error}'));
} else if (snapshot.hasData) {
- // Convert the protobuf data to a Flutter widget
- // This will use our SduiProtoParser to create the widget tree
+ // Parse the protobuf data and convert to Flutter widget
final SduiWidget sduiWidget = SduiParser.parseProto(snapshot.data!);
return sduiWidget.toFlutterWidget();
} else {
diff --git a/lib/src/service/sdui_grpc_client.dart b/lib/src/service/sdui_grpc_client.dart
index f5e1200..5c0c19d 100644
--- a/lib/src/service/sdui_grpc_client.dart
+++ b/lib/src/service/sdui_grpc_client.dart
@@ -1,12 +1,36 @@
import 'package:grpc/grpc.dart';
import 'package:flutter_sdui/src/generated/sdui.pbgrpc.dart';
-/// A client for the SDUI gRPC service.
+/// A gRPC client for communicating with SDUI servers.
+///
+/// This client handles the network communication between the Flutter app
+/// and the server that provides the UI definitions. It manages the gRPC
+/// connection lifecycle and provides methods to fetch widget data.
+///
+/// Example usage:
+/// ```dart
+/// final client = SduiGrpcClient(
+/// host: 'your-server.com',
+/// port: 50051,
+/// secure: true,
+/// );
+///
+/// final widgetData = await client.getWidget('home_screen');
+/// ```
class SduiGrpcClient {
late final SduiServiceClient _client;
late final ClientChannel _channel;
/// Creates a new SDUI gRPC client.
+ ///
+ /// Parameters:
+ /// * [host] - The hostname or IP address of the gRPC server
+ /// * [port] - The port number the gRPC server is listening on
+ /// * [secure] - Whether to use secure (TLS) connection. Defaults to false
+ ///
+ /// The client will establish a connection to the server immediately upon
+ /// construction. Call [dispose] when the client is no longer needed to
+ /// properly close the connection.
SduiGrpcClient({
required String host,
required int port,
@@ -25,13 +49,24 @@ class SduiGrpcClient {
_client = SduiServiceClient(_channel);
}
- /// Fetches a UI widget from the server.
+ /// Fetches widget data from the server for the specified screen.
+ ///
+ /// [screenId] is a server-defined identifier that specifies which
+ /// UI definition to retrieve. The server should return a complete
+ /// widget tree definition for the requested screen.
+ ///
+ /// Returns a [Future] that completes with the widget data, or throws
+ /// a [GrpcError] if the request fails.
Future getWidget(String screenId) async {
final request = SduiRequest()..screenId = screenId;
return _client.getSduiWidget(request);
}
- /// Closes the connection to the server.
+ /// Closes the connection to the server and releases all resources.
+ ///
+ /// This method should be called when the client is no longer needed
+ /// to properly clean up the gRPC connection. After calling this method,
+ /// the client should not be used for any further operations.
Future dispose() async {
await _channel.shutdown();
}
diff --git a/lib/src/widgets/sdui_column.dart b/lib/src/widgets/sdui_column.dart
index f47b38f..d05bfdc 100644
--- a/lib/src/widgets/sdui_column.dart
+++ b/lib/src/widgets/sdui_column.dart
@@ -1,16 +1,40 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents a Column widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [Column] widget.
+///
+/// This widget displays its children in a vertical array, allowing for
+/// flexible layout configuration through server-defined properties.
+///
+/// The column's layout behavior can be controlled through alignment,
+/// sizing, and direction properties that mirror Flutter's Column widget.
class SduiColumn extends SduiWidget {
+ /// The widgets below this widget in the tree.
final List children;
+
+ /// How the children should be placed along the main axis (vertically).
final MainAxisAlignment? mainAxisAlignment;
+
+ /// How much space should be occupied in the main axis.
final MainAxisSize? mainAxisSize;
+
+ /// How the children should be placed along the cross axis (horizontally).
final CrossAxisAlignment? crossAxisAlignment;
+
+ /// Determines the order to lay children out horizontally.
final TextDirection? textDirection;
+
+ /// Determines the order to lay children out vertically.
final VerticalDirection? verticalDirection;
+
+ /// The baseline to use when aligning text within the column.
final TextBaseline? textBaseline;
+ /// Creates a new [SduiColumn] widget.
+ ///
+ /// The [children] parameter is required and defines the widgets to be
+ /// laid out vertically. All other parameters are optional and control
+ /// the layout behavior.
SduiColumn({
required this.children,
this.mainAxisAlignment,
diff --git a/lib/src/widgets/sdui_container.dart b/lib/src/widgets/sdui_container.dart
index ad2739e..2ed26d0 100644
--- a/lib/src/widgets/sdui_container.dart
+++ b/lib/src/widgets/sdui_container.dart
@@ -1,21 +1,57 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents a Container widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [Container] widget.
+///
+/// This widget combines common painting, positioning, and sizing widgets
+/// into a single convenient widget. It's one of the most versatile widgets
+/// in the SDUI toolkit, supporting decoration, padding, margins, constraints,
+/// and transformations.
+///
+/// Note: The [color] parameter is only applied when [decoration] is null.
+/// If both are specified, [decoration] takes precedence.
class SduiContainer extends SduiWidget {
+ /// The widget below this widget in the tree.
final SduiWidget? child;
+
+ /// Empty space to inscribe inside the decoration. The child is placed inside this padding.
final EdgeInsets? padding;
+
+ /// Empty space to surround the decoration and child.
final EdgeInsets? margin;
- final BoxDecoration? decoration; // Handles color, borderRadius, border, etc.
+
+ /// The decoration to paint behind the child.
+ /// Handles background color, border radius, borders, shadows, and gradients.
+ final BoxDecoration? decoration;
+
+ /// If non-null, requires the child to have exactly this width.
final double? width;
+
+ /// If non-null, requires the child to have exactly this height.
final double? height;
+
+ /// The color to paint behind the child. Only used when [decoration] is null.
final Color? color;
+
+ /// Aligns the child within the container.
final Alignment? alignment;
+
+ /// Additional constraints to apply to the child.
final BoxConstraints? constraints;
+
+ /// The transformation matrix to apply before painting the container.
final Matrix4? transform;
+
+ /// The alignment of the origin for the transformation.
final AlignmentGeometry? transformAlignment;
+
+ /// The clip behavior for the container's contents.
final Clip? clipBehavior;
+ /// Creates a new [SduiContainer] widget.
+ ///
+ /// All parameters are optional. The container's appearance and behavior
+ /// are determined by the combination of properties provided.
SduiContainer({
this.child,
this.padding,
@@ -39,9 +75,8 @@ class SduiContainer extends SduiWidget {
decoration: decoration,
width: width,
height: height,
- color: decoration == null
- ? color
- : null, // Only use color if decoration is null
+ // Only use color if decoration is null to avoid conflicts
+ color: decoration == null ? color : null,
alignment: alignment,
constraints: constraints,
transform: transform,
diff --git a/lib/src/widgets/sdui_icon.dart b/lib/src/widgets/sdui_icon.dart
index a428418..2a4023a 100644
--- a/lib/src/widgets/sdui_icon.dart
+++ b/lib/src/widgets/sdui_icon.dart
@@ -1,18 +1,46 @@
+import 'dart:developer';
+
import 'package:flutter/material.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents an Icon widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [Icon] widget.
+///
+/// This widget displays a graphical icon from Flutter's built-in icon sets
+/// or custom icon fonts. It supports comprehensive styling options including
+/// size, color, shadows, and opacity.
+///
+/// The widget can handle missing icon data gracefully by rendering an empty
+/// widget instead of throwing an error.
class SduiIcon extends SduiWidget {
+ /// The icon to display. If null, an empty widget will be rendered.
final IconData? icon;
+
+ /// The size of the icon in logical pixels.
final double? size;
+
+ /// The color to use when drawing the icon.
final Color? color;
+
+ /// Semantic description of the icon for accessibility.
final String? semanticLabel;
+
+ /// The text direction to use for resolving the icon.
final TextDirection? textDirection;
- final double?
- opacity; // Custom property for opacity - will use Opacity widget
+
+ /// The opacity to apply to the icon. Values should be between 0.0 and 1.0.
+ final double? opacity;
+
+ /// Whether to scale the icon based on the text scale factor.
final bool? applyTextScaling;
+
+ /// A list of shadows to cast behind the icon.
final List? shadows;
+ /// Creates a new [SduiIcon] widget.
+ ///
+ /// All parameters are optional. If [icon] is null, an empty widget
+ /// will be rendered. The [opacity] will be applied using an [Opacity]
+ /// widget if the value is less than 1.0.
SduiIcon({
this.icon,
this.size,
@@ -26,7 +54,7 @@ class SduiIcon extends SduiWidget {
String? get iconName {
if (icon == null) return null;
-
+
const codePointToName = {
0xe8b8: 'settings',
0xe88a: 'home',
@@ -36,7 +64,7 @@ class SduiIcon extends SduiWidget {
0xe88e: 'info',
0xe318: 'home',
};
- print(codePointToName);
+ log(codePointToName.toString());
return codePointToName[icon!.codePoint];
}
@@ -56,7 +84,7 @@ class SduiIcon extends SduiWidget {
applyTextScaling: applyTextScaling,
);
- // Apply opacity if provided
+ // Apply opacity wrapper if needed
if (opacity != null && opacity! < 1.0) {
iconWidget = Opacity(
opacity: opacity!,
diff --git a/lib/src/widgets/sdui_image.dart b/lib/src/widgets/sdui_image.dart
index ee7c22d..3b1e66c 100644
--- a/lib/src/widgets/sdui_image.dart
+++ b/lib/src/widgets/sdui_image.dart
@@ -1,27 +1,78 @@
+import 'dart:developer';
+
import 'package:flutter/widgets.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents an Image widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [Image] widget.
+///
+/// This widget supports displaying images from network URLs with comprehensive
+/// customization options for sizing, alignment, color blending, and caching.
+///
+/// Currently, only network images (URLs starting with 'http') are supported.
+/// Local assets and file system images are not yet implemented.
+///
+/// The widget provides loading and error handling capabilities through
+/// optional custom widgets.
class SduiImage extends SduiWidget {
- final String src; // Network URL
+ /// The network URL of the image to display.
+ final String src;
+
+ /// If non-null, requires the image to have exactly this width.
final double? width;
+
+ /// If non-null, requires the image to have exactly this height.
final double? height;
+
+ /// How the image should be inscribed into the space allocated during layout.
final BoxFit? fit;
+
+ /// How to align the image within its bounds.
final Alignment? alignment;
+
+ /// How the image should be repeated if it doesn't fill its layout bounds.
final ImageRepeat? repeat;
+
+ /// A color to blend with the image.
final Color? color;
+
+ /// The blend mode to use when applying the color.
final BlendMode? colorBlendMode;
+
+ /// The center slice for a nine-patch image.
final Rect? centerSlice;
+
+ /// Whether to paint the image in the direction of the text.
final bool? matchTextDirection;
+
+ /// Whether to continue showing the old image when the new image fails to load.
final bool? gaplessPlayback;
+
+ /// The quality level to use when scaling the image.
final FilterQuality? filterQuality;
+
+ /// The target width for image caching.
final int? cacheWidth;
+
+ /// The target height for image caching.
final int? cacheHeight;
+
+ /// The scale to place in the ImageInfo object of the image.
final double? scale;
+
+ /// A semantic description of the image for accessibility.
final String? semanticLabel;
+
+ /// Widget to display when an error occurs while loading the image.
final Widget? errorWidget;
+
+ /// Widget to display while the image is loading.
final Widget? loadingWidget;
+ /// Creates a new [SduiImage] widget.
+ ///
+ /// The [src] parameter is required and must be a valid network URL.
+ /// All other parameters are optional and provide customization for
+ /// image display and behavior.
SduiImage(
this.src, {
this.width,
@@ -73,9 +124,8 @@ class SduiImage extends SduiWidget {
: null,
);
} else {
- // Optionally, return a placeholder or throw an error for non-network images.
- // For now, returning an empty SizedBox.
- print(
+ // Return empty widget for non-network URLs with warning
+ log(
"Warning: SduiImage currently only supports network images. Provided src: $src");
return const SizedBox.shrink();
}
diff --git a/lib/src/widgets/sdui_row.dart b/lib/src/widgets/sdui_row.dart
index 7962e88..5c13cf2 100644
--- a/lib/src/widgets/sdui_row.dart
+++ b/lib/src/widgets/sdui_row.dart
@@ -1,16 +1,40 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents a Row widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [Row] widget.
+///
+/// This widget displays its children in a horizontal array, allowing for
+/// flexible layout configuration through server-defined properties.
+///
+/// The row's layout behavior can be controlled through alignment,
+/// sizing, and direction properties that mirror Flutter's Row widget.
class SduiRow extends SduiWidget {
+ /// The widgets below this widget in the tree.
final List children;
+
+ /// How the children should be placed along the main axis (horizontally).
final MainAxisAlignment? mainAxisAlignment;
+
+ /// How much space should be occupied in the main axis.
final MainAxisSize? mainAxisSize;
+
+ /// How the children should be placed along the cross axis (vertically).
final CrossAxisAlignment? crossAxisAlignment;
+
+ /// Determines the order to lay children out horizontally.
final TextDirection? textDirection;
+
+ /// Determines the order to lay children out vertically.
final VerticalDirection? verticalDirection;
+
+ /// The baseline to use when aligning text within the row.
final TextBaseline? textBaseline;
+ /// Creates a new [SduiRow] widget.
+ ///
+ /// The [children] parameter is required and defines the widgets to be
+ /// laid out horizontally. All other parameters are optional and control
+ /// the layout behavior.
SduiRow({
required this.children,
this.mainAxisAlignment,
diff --git a/lib/src/widgets/sdui_scaffold.dart b/lib/src/widgets/sdui_scaffold.dart
index 8dfdf1c..79e5128 100644
--- a/lib/src/widgets/sdui_scaffold.dart
+++ b/lib/src/widgets/sdui_scaffold.dart
@@ -1,26 +1,75 @@
-import 'package:flutter/material.dart'; // Scaffold is in material.dart
+import 'dart:developer';
+
+import 'package:flutter/material.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents a Scaffold widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [Scaffold] widget.
+///
+/// This widget implements the basic material design visual layout structure.
+/// It provides slots for the most common components of a screen, such as
+/// app bars, bodies, floating action buttons, and drawers.
+///
+/// The scaffold ensures proper Material Design layout behavior and manages
+/// component positioning and sizing automatically.
+///
+/// Note: The [appBar] widget must resolve to a [PreferredSizeWidget]
+/// (such as an AppBar) to be properly displayed.
class SduiScaffold extends SduiWidget {
+ /// An app bar to display at the top of the scaffold.
final SduiWidget? appBar;
+
+ /// The primary content of the scaffold.
final SduiWidget? body;
+
+ /// A floating action button displayed over the body.
final SduiWidget? floatingActionButton;
+
+ /// A bottom navigation bar to display at the bottom of the scaffold.
final SduiWidget? bottomNavigationBar;
+
+ /// A navigation drawer that slides in from the left side.
final SduiWidget? drawer;
+
+ /// A navigation drawer that slides in from the right side.
final SduiWidget? endDrawer;
+
+ /// A bottom sheet displayed above the scaffold body.
final SduiWidget? bottomSheet;
+
+ /// The color of the scaffold's background.
final Color? backgroundColor;
+
+ /// Whether the body should resize when the keyboard appears.
final bool? resizeToAvoidBottomInset;
+
+ /// Whether this scaffold is being displayed at the top of the screen.
final bool? primary;
+
+ /// The position of the floating action button.
final FloatingActionButtonLocation? floatingActionButtonLocation;
+
+ /// Whether the body should extend behind the app bar.
final bool? extendBody;
+
+ /// Whether the body should extend behind the app bar when fully expanded.
final bool? extendBodyBehindAppBar;
+
+ /// The color to use for the scrim that obscures primary content while a drawer is open.
final Color? drawerScrimColor;
+
+ /// The width of the area within which a horizontal swipe will open the drawer.
final double? drawerEdgeDragWidth;
+
+ /// Whether the drawer can be opened with a drag gesture.
final bool? drawerEnableOpenDragGesture;
+
+ /// Whether the end drawer can be opened with a drag gesture.
final bool? endDrawerEnableOpenDragGesture;
+ /// Creates a new [SduiScaffold] widget.
+ ///
+ /// All parameters are optional. The scaffold will display only the
+ /// components that are provided.
SduiScaffold({
this.appBar,
this.body,
@@ -45,20 +94,12 @@ class SduiScaffold extends SduiWidget {
Widget toFlutterWidget() {
Widget? flutterAppBar;
if (appBar != null) {
- // Attempt to cast to PreferredSizeWidget. This assumes the SDUI appBar resolves to something like AppBar.
- // More robust handling might be needed if it can be any widget.
- // For now, we expect it to be a widget that can be an AppBar (e.g. SduiContainer styled as an AppBar)
- // or a custom SduiAppBar widget if we introduce one.
- var potentialAppBar = appBar!.toFlutterWidget();
+ final potentialAppBar = appBar!.toFlutterWidget();
if (potentialAppBar is PreferredSizeWidget) {
flutterAppBar = potentialAppBar;
} else {
- // If it's not a PreferredSizeWidget, wrap it in one if possible or log a warning.
- // For simplicity, we are strict for now. Consider a SduiAppBar sdui widget for proper typing.
- print(
+ log(
"Warning: appBar widget for SduiScaffold is not a PreferredSizeWidget. It might not render correctly.");
- // As a fallback, one might wrap it in a simple PreferredSize if it has a defined height.
- // flutterAppBar = PreferredSize(child: potentialAppBar, preferredSize: Size.fromHeight(kToolbarHeight));
}
}
diff --git a/lib/src/widgets/sdui_sized_box.dart b/lib/src/widgets/sdui_sized_box.dart
index 3feb28e..1eb7de5 100644
--- a/lib/src/widgets/sdui_sized_box.dart
+++ b/lib/src/widgets/sdui_sized_box.dart
@@ -1,12 +1,29 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents a SizedBox widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [SizedBox] widget.
+///
+/// This widget forces its child to have a specific width and/or height.
+/// It's useful for creating fixed-size layouts or adding spacing between widgets.
+///
+/// If no dimensions are specified, the widget will try to be as big as possible.
+/// If only one dimension is specified, the widget will try to be as big as
+/// possible in the other dimension.
class SduiSizedBox extends SduiWidget {
+ /// The width to constrain the child to.
final double? width;
+
+ /// The height to constrain the child to.
final double? height;
+
+ /// The widget below this widget in the tree.
final SduiWidget? child;
+ /// Creates a new [SduiSizedBox] widget.
+ ///
+ /// All parameters are optional. If neither [width] nor [height] are
+ /// specified, the child will be unconstrained. If only one dimension
+ /// is specified, the child will be constrained in that dimension only.
SduiSizedBox({this.width, this.height, this.child});
@override
diff --git a/lib/src/widgets/sdui_spacer.dart b/lib/src/widgets/sdui_spacer.dart
index 4095f41..5d33740 100644
--- a/lib/src/widgets/sdui_spacer.dart
+++ b/lib/src/widgets/sdui_spacer.dart
@@ -1,10 +1,24 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents a Spacer widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [Spacer] widget.
+///
+/// This widget creates an adjustable, empty spacer that can be used to tune
+/// the spacing between widgets in a [Flex] container, like [Row] or [Column].
+///
+/// The spacer takes up space proportional to its [flex] value relative to
+/// other flexible widgets in the same container.
class SduiSpacer extends SduiWidget {
+ /// The flex factor to use for determining how much space to take up.
+ ///
+ /// The amount of space this widget takes up is proportional to its [flex]
+ /// value divided by the total flex values of all widgets in the container.
final int flex;
+ /// Creates a new [SduiSpacer] widget.
+ ///
+ /// The [flex] parameter defaults to 1, which means the spacer will take
+ /// up an equal amount of space as other spacers with the same flex value.
SduiSpacer({this.flex = 1});
@override
diff --git a/lib/src/widgets/sdui_text.dart b/lib/src/widgets/sdui_text.dart
index 331869f..9a9a1d0 100644
--- a/lib/src/widgets/sdui_text.dart
+++ b/lib/src/widgets/sdui_text.dart
@@ -1,24 +1,64 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_sdui/src/widgets/sdui_widget.dart';
-/// Represents a Text widget in SDUI.
+/// A server-driven UI widget that represents a Flutter [Text] widget.
+///
+/// This widget allows displaying text with customizable styling properties
+/// that can be defined on the server side and rendered on the client.
+///
+/// The widget supports all common text properties including font styling,
+/// alignment, overflow handling, and text direction.
class SduiText extends SduiWidget {
+ /// The text content to display.
final String text;
+
+ /// The text style to apply. This can be merged with individual style properties.
final TextStyle? style;
+
+ /// How the text should be aligned horizontally.
final TextAlign? textAlign;
+
+ /// How visual overflow should be handled.
final TextOverflow? overflow;
+
+ /// An optional maximum number of lines for the text to span.
final int? maxLines;
+
+ /// The decoration to paint near the text (e.g., underline).
final TextDecoration? decoration;
+
+ /// The size of glyphs (in logical pixels) to use when painting the text.
final double? fontSize;
+
+ /// The typeface thickness to use when painting the text.
final FontWeight? fontWeight;
+
+ /// The color to use when painting the text.
final Color? color;
+
+ /// Whether the text should break at soft line breaks.
final bool? softWrap;
+
+ /// The amount of space (in logical pixels) to add between each letter.
final double? letterSpacing;
+
+ /// The amount of space (in logical pixels) to add at each sequence of white-space.
final double? wordSpacing;
+
+ /// The height of this text span, as a multiple of the font size.
final double? height;
+
+ /// The name of the font to use when painting the text.
final String? fontFamily;
+
+ /// The directionality of the text.
final TextDirection? textDirection;
+ /// Creates a new [SduiText] widget.
+ ///
+ /// The [text] parameter is required and specifies the content to display.
+ /// All other parameters are optional and can be used to customize the
+ /// appearance and behavior of the text.
SduiText(
this.text, {
this.style,
@@ -39,8 +79,8 @@ class SduiText extends SduiWidget {
@override
Widget toFlutterWidget() {
- // Create a merged TextStyle that combines the individual properties with the style
- TextStyle mergedStyle = (style ?? const TextStyle()).copyWith(
+ // Merge individual style properties with the base style
+ final TextStyle mergedStyle = (style ?? const TextStyle()).copyWith(
decoration: decoration,
fontSize: fontSize,
fontWeight: fontWeight,
diff --git a/lib/src/widgets/sdui_widget.dart b/lib/src/widgets/sdui_widget.dart
index 2b01502..d50a7b4 100644
--- a/lib/src/widgets/sdui_widget.dart
+++ b/lib/src/widgets/sdui_widget.dart
@@ -1,6 +1,20 @@
import 'package:flutter/widgets.dart';
-/// Abstract class for all SDUI widgets.
+/// Abstract base class for all Server-Driven UI widgets.
+///
+/// This class defines the contract that all SDUI widgets must implement.
+/// Each SDUI widget can be converted to its corresponding Flutter widget
+/// through the [toFlutterWidget] method.
+///
+/// All concrete SDUI widget implementations should extend this class and
+/// provide their own implementation of [toFlutterWidget].
abstract class SduiWidget {
+ /// Converts this SDUI widget to its corresponding Flutter widget.
+ ///
+ /// This method is responsible for mapping the SDUI widget's properties
+ /// to the equivalent Flutter widget properties and returning a fully
+ /// configured Flutter widget instance.
+ ///
+ /// Returns a [Widget] that can be rendered in the Flutter widget tree.
Widget toFlutterWidget();
}
diff --git a/pubspec.yaml b/pubspec.yaml
index fe72900..522644f 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,7 +1,8 @@
name: flutter_sdui
-description: "A Flutter package to render server driven UI."
+description: "A Flutter package for Server-Driven UI with JSON and gRPC support. Build dynamic UIs updated from the server without app releases."
version: 0.0.1
-# homepage:
+homepage: https://github.com/GDGVIT/flutter-sdui-package
+repository: https://github.com/GDGVIT/flutter-sdui-package
environment:
sdk: ">=3.0.0 <4.0.0"
diff --git a/test/flutter_sdui_test.dart b/test/flutter_sdui_test.dart
index 120d6ec..d810967 100644
--- a/test/flutter_sdui_test.dart
+++ b/test/flutter_sdui_test.dart
@@ -1,37 +1,34 @@
-// import 'package:flutter_test/flutter_test.dart';
-
-// import 'package:flutter_sdui/flutter_sdui.dart';
-
-// void main() {
-// test('adds one to input values', () {
-// final calculator = Calculator();
-// expect(calculator.addOne(2), 3);
-// expect(calculator.addOne(-7), -6);
-// expect(calculator.addOne(0), 1);
-// });
-// }
+import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_sdui/src/parser/sdui_proto_parser.dart';
+/// Main test entry point for Flutter SDUI package.
+///
+/// This test demonstrates JSON parsing functionality by loading an example
+/// JSON file, parsing it into SDUI widgets, and rendering as Flutter widgets.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
- // Load the example JSON file
- final file = File('example/example.json');
- final jsonString = await file.readAsString();
- final Map jsonData = json.decode(jsonString);
+ group('Flutter SDUI Tests', () {
+ test('JSON parsing and widget conversion', () async {
+ final file = File('example/example.json');
+ final jsonString = await file.readAsString();
+ final Map jsonData = json.decode(jsonString);
- // Parse the JSON into an SDUI widget
- final sduiWidget = SduiParser.parseJSON(jsonData);
+ final sduiWidget = SduiParser.parseJSON(jsonData);
+ final widget = sduiWidget.toFlutterWidget();
- // Convert to Flutter widget
- final widget = sduiWidget.toFlutterWidget();
+ expect(widget, isA());
+ expect(sduiWidget, isNotNull);
+ });
- runApp(MaterialApp(
- home: widget,
- ));
-}
+ test('SDUI parser handles empty JSON', () {
+ final emptyJson = {};
+ expect(() => SduiParser.parseJSON(emptyJson), throwsA(isA()));
+ });
+ });
+}