{"id":6340,"date":"2025-04-10T09:34:44","date_gmt":"2025-04-10T09:34:44","guid":{"rendered":"https:\/\/obsidiansofteducation.com\/?page_id=6340"},"modified":"2025-04-10T09:34:52","modified_gmt":"2025-04-10T09:34:52","slug":"dynamic-components-in-mit-app-inventor","status":"publish","type":"page","link":"https:\/\/obsidiansofteducation.com\/index.php\/dynamic-components-in-mit-app-inventor\/","title":{"rendered":"How to add Dynamic Components in MIT App Inventor &#8211; Dynamic Chatting App or Chatbot"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\">Hello friends,<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Welcome to Obsidian Soft!<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">In this tutorial, I will teach you how to add dynamic components to your MIT App Inventor app to give a more elegant look to your apps. You can use such dynamic components such as dynamic labels in chatting apps or chatbots to give a WhatsApp or Facebook Messenger like professional look. The following picture shows a Gemini AI chatbot built using dynamic components.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"492\" height=\"997\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/ApplicationFrameHost_DHEAJYIe4n-1.png\" alt=\"\" class=\"wp-image-6341\" style=\"width:233px;height:auto\" srcset=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/ApplicationFrameHost_DHEAJYIe4n-1.png 492w, https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/ApplicationFrameHost_DHEAJYIe4n-1-148x300.png 148w\" sizes=\"auto, (max-width: 492px) 100vw, 492px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For this, we need an amazing extension and a big round of applause for the developer!<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Download the dynamic components extension:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/github.com\/ysfchn\/DynamicComponents-AI2\/releases\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/ysfchn\/DynamicComponents-AI2\/releases<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Open up MIT App Inventor. <\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/ai2.appinventor.mit.edu\" target=\"_blank\" rel=\"noopener\">https:\/\/ai2.appinventor.mit.edu<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Start a new project in MIT App Inventor or open a preexisting one (<a href=\"https:\/\/obsidiansofteducation.com\/index.php\/google_gemin_ai_mit_app_inventor_tutorial\/\">if you are coming here after making a basic Google Gemini AI Chatbot in MIT App Inventor)<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color has-medium-font-size wp-elements-801239f191f5d521faefcbed9c502e63 wp-block-paragraph\"><strong>Follow the following steps only if you are working on your <\/strong><a href=\"https:\/\/obsidiansofteducation.com\/index.php\/google_gemin_ai_mit_app_inventor_tutorial\/\"><strong>Gemini Google AI Chatbot<\/strong> <strong>preexisting project<\/strong><\/a><strong>:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><em>Remove the temporary label that we had placed in the vertical scroll arrangement.<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-link-color has-medium-font-size wp-elements-6bcd852fdcfdfc3c0f583a7dba42a33f wp-block-paragraph\"><strong>Follow the following steps only if you are working on a new project:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><em>Make screen orientation portrait. Add a Horizontal Arrangement from Layouts palette onto the viewer. Make align horizontal and align vertical both center in the arrangement&#8217;s properties. Also, make width fill parent and height 15%. Drag and drop a text box and button from the user interface palette in this horizontal arrangement. Rename the button to submitBtn. In its properties, change text to <strong>Submit <\/strong>and make background color of button: orange. Drag a Vertical Scroll Arrangement from Layouts below the horizontal arrangement. Make the width fill parent and height 75%.<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-d430f902a20d78dcbd0ecd8cc0ff015a wp-block-paragraph\">Import the downloaded extension under extensions tab on the left. After a successful import, drag its component onto the viewer. <\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Our UX design is done so go to the blocks section.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Add a global variable for msgCounter initialized to 1 and a variable for color initialized to any color you want.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/AD_4nXck6v0QZN1rZme0rWgRKYGXEVgaEezSQlhe_8P2ogRegD7-_MH7JiesEEfGJ2eSJWao-6KrAYVJ3fS3aV7kApyFX6kpklmIG9XNzSFYKf5enQZqgSc3LdmE8kabX7cg_NEBzIYl3wkeyxukgIDFo4ann8_fV18K_Tm6G.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/AD_4nXc9O69JRIbX-3ptWitI5jiw9ncfzFPNQJEy671tc5AARJxZVbl2DIg27HQN-XP2HZFDcXreZz19n1KIe67TmwsmhVWcSP6NXqSbEp9S0dAoUNGNX39p4AuTrFkvEnCsdLe0g5VZNQkeyxukgIDFo4ann8_fV18K_Tm6G.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Make a procedure called AddMessageBubble that takes in two inputs isUser and message. You will need to click on the cog wheel to add input variables. The isUser input variable is only needed if you are making a chatbot or chatting app where you want to distinguish between messages entered by user and messages by other people or the chatbot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/AD_4nXch5Y0QdytT8lY27i7wBjuIeYpzrbTRpH50zAYR3sGimCSfwvg7hFBDaCOkWhrAPU_ck1J8ACmC_gEeoMpQwoBLf1s-B0wT7-5fi8BtPT8CTf9qMefxHF2VISDKWsrF182N6MXn4AkeyxukgIDFo4ann8_fV18K_Tm6G.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Make a local variable id and it should be a join of the word \u201cmsg\u201d and msgCounter.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Make a local variable labelId and it should be a join of id and word \u201cLbl\u201d<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Next, increment the msgCounter global variable i.e. add 1 to it.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Now, create a dynamic horizontal arrangement in the chatScroll (the vertical scroll arrangement) and give it a width of fill parent by setting Width property to -2.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/AD_4nXdw9Z9svnSXqNbLdijzyA598CI0A3nFmuDIjIcpDM2RovQJ-TMd8YbjBwzSnQFOlnkLbDYFGZUgh-5hvSHxBhW2YEcRBemU24SaBEElXpVDmGd0yLur7E57yJLmxxPB6Ug7Xe-KvAkeyxukgIDFo4ann8_fV18K_Tm6G.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Next, we are going to check if isUser is true because this means that this message was entered by the user and should have a different background color. Use light colors so that black text looks prominent on them. We set the color global variable differently depending on isUser and we also align the horizontal arrangement towards the right if isUser and left if not isUser.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/AD_4nXeEi_LDTBYPuulO6Yv99ur1518UlM4MKqJUvr9Ntgnm9EdBD_w7bT8C6kyMrxE8dD6yWr14SgeGANGxzyBsKFYUbES2j1NO23G9_ac5a1dm7WzZ1mx4Xn7SxXRO_PZBu63p7QmIIwkeyxukgIDFo4ann8_fV18K_Tm6G.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Next, we are going to actually add a label inside this dynamic horizontal arrangement and then set its properties.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/AD_4nXe_gCkAR4kLuWFX0K7_psEyUWKmEm7Zsg0iGM4H6muIGpmCcRk7kXjF2z2B46xpfstq3Za3IKabzJMnd3mhyDjdOJI8UVyyHar33Wqf0mfr57OSSS-amKBoQEtejHfX63p7X4C5owkeyxukgIDFo4ann8_fV18K_Tm6G.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">It is super important while using the dynamic components extension that you use exact spellings as shown in this tutorial.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Now, call this procedure when you need to create such dynamic labels. Remember to provide an isUser value as true or false depending on if the message is by the user or by someone else.<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color has-medium-font-size wp-elements-0329e3b4dde7fd8375ed7b7a44b4d593 wp-block-paragraph\"><strong>The following code demonstrates where to call it if you are making a Google Gemini AI Chatbot app:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><em>We need to call this procedure from two places. At the beginning of sendBtn click event:<\/em><br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/AD_4nXelwmRCduPHBIMz7hIJovYhY9EmfKE3RBrb0p2wRyd-M7nP1ist53eaRR-V5RxCSwCfaA7kRCtMkgoRLarg8WrohTe2ljoZwl6OS_qUQ8rlG0ixaLkTNhETJUQCZGaps6V5Tk0h1AkeyxukgIDFo4ann8_fV18K_Tm6G.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><em>And at the end of web1.gotText event where we had previously placed the setting of the temporary label.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/04\/AD_4nXe7DEW2mqAkKEwnO7lSJj5Dx5rQUoUmk9uN3f_FtBUWMf-efp-cQd3bX0VphUKUXfCCGIpL3VHCIosV-lDQi2mDQ6e5p4qTXW_wHBYBunw-K7wp4MsPOf8p4rp7WEYrxPlWP7MH_wkeyxukgIDFo4ann8_fV18K_Tm6G.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><em>And now your chat with Gemini will look like the demo.<\/em><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">I hope you found this tutorial useful and educational.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">You can have a look at the video tutorial too:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<p class=\"responsive-video-wrap clr\"><iframe loading=\"lazy\" title=\"MIT App Inventor Chatbot - Google AI Gemini - Pt 2 : How to add Dynamic Components in App Inventor\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/2nv0ylKeT8Q?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<\/div><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my videos and share them with your friends and family. Also, subscribe to my channel and press the bell icon so you don\u2019t miss any of the great projects I have planned for you:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/www.youtube.com\/c\/obsidiansofteducation\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/c\/obsidiansofteducation<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my social media pages for more educational resources and tips.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Facebook:<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">&nbsp;https:\/\/www.facebook.com\/ObsidianSoft\/<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Instagram:<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">&nbsp;https:\/\/www.instagram.com\/obsidiansoftapps\/<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Pinterest:&nbsp;<a href=\"https:\/\/www.pinterest.com\/obsidiansoft\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.pinterest.com\/obsidiansoft\/<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For links to free educational apps, have a look at the&nbsp;<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">educational apps page<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello friends, Welcome to Obsidian Soft! In this tutorial, I will teach you how to add dynamic components to your MIT App Inventor app to give a more elegant look to your apps. You can use such dynamic components such as dynamic labels in chatting apps or chatbots to give a WhatsApp or Facebook Messenger [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6340","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/6340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/comments?post=6340"}],"version-history":[{"count":1,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/6340\/revisions"}],"predecessor-version":[{"id":6350,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/6340\/revisions\/6350"}],"wp:attachment":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/media?parent=6340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}