<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mwai on Medium]]></title>
        <description><![CDATA[Stories by Mwai on Medium]]></description>
        <link>https://medium.com/@machariamwai?source=rss-d04eebbdb2a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IkzYC5p11tlHQlkO7TBc2A.jpeg</url>
            <title>Stories by Mwai on Medium</title>
            <link>https://medium.com/@machariamwai?source=rss-d04eebbdb2a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 18:01:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@machariamwai/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Two Simple Ways to Use Google Fonts In Your Flutter App]]></title>
            <link>https://machariamwai.medium.com/two-simple-ways-to-use-google-fonts-in-your-flutter-app-a298f962b1b4?source=rss-d04eebbdb2a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a298f962b1b4</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[google-fonts]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mwai]]></dc:creator>
            <pubDate>Mon, 20 Nov 2023 12:11:12 GMT</pubDate>
            <atom:updated>2023-11-20T12:11:12.965Z</atom:updated>
            <content:encoded><![CDATA[<p>In Flutter, fonts play a pivotal role in shaping the visual identity and design aesthetics of a mobile application. The default font on Android is Roboto and on iOS it is .SF UI Display or .SF UI Text .</p><p>So what to do if I want to use Google Fonts in my Flutter application? This article will show you to use the <a href="https://pub.dev/packages/google_fonts">google_fonts</a> package in your Flutter application to access fonts from fonts.google.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KZRjos180pGnoN8H" /><figcaption>Photo by <a href="https://unsplash.com/@jontyson?utm_source=medium&amp;utm_medium=referral">Jon Tyson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>You can add the google_fonts package by either running this command in your terminal:</p><pre>flutter pub add google_fonts</pre><p>Or adding this line in your package’s pubspec.yaml</p><pre>dependencies:<br>  google_fonts: ^6.1.0</pre><p>Run flutter pub get in your terminal if your IDE doesn’t do it after you add the above line.</p><p>Our app at this point looks like this, as it is still using the Roboto font.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*B254WwRV1WnswWb3URvg8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqbJKJAqepHRQrAKC9k5Iw.png" /></figure><p>Now in your Dart code, import Google Fonts like:</p><pre>import &#39;package:google_fonts/google_fonts.dart&#39;;</pre><p>Now to our first method, this method would be perfect if you only wanted to use your preffered Google Font once. Use the Google Font with an existing TextStyle like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-X-J8gmPXwKZPSY3DzomQ.png" /></figure><p>Our app after adding the code above looks as seen below. Note that only the title uses the Poppins font.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*pFMlMiStd56vBDLhbKJYFQ.png" /></figure><p>Now imagine you want to use a font through your entire application. in your main.dart file or your theme file, add a TextTheme and add your preferred font as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eXix5mSMQe94orBtNxBVWA.png" /></figure><p>Note how all the text is now using the Poppins font.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*CfcCUYn8jB8_ZX_qljWO0A.png" /></figure><p>To learn more about how to use different Google Fonts in your app using TextTheme visit <a href="https://pub.dev/packages/google_fonts">google_fonts</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a298f962b1b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Favorite React Hook (And How To Use It To Create A Dark Theme For Your Website).]]></title>
            <link>https://machariamwai.medium.com/my-favorite-react-hook-and-how-to-use-it-to-create-a-dark-theme-for-your-website-1bc30a578c8a?source=rss-d04eebbdb2a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bc30a578c8a</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mwai]]></dc:creator>
            <pubDate>Fri, 27 May 2022 18:19:32 GMT</pubDate>
            <atom:updated>2022-05-31T09:15:10.916Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><a href="https://nighteye.app/dark-mode/#:~:text=According%20to%20a%20recent%20study,to%2063%25%20on%20AMOLED%20displays.">According to a recent study</a>, 82% of people use dark mode on their phones. About 83% use their operating system’s on dark mode. 65% of those who responded expect websites to automatically apply a dark theme. Dark mode has also been found to reduce battery usage up to 63% on AMOLED displays. And in a class of about 30 students and two mentors, I have yet to come across anyone using light mode on their IDE. So why not give the web users what they want?</blockquote><p>This is where my favorite React hook comes into play. But what is React and what are hooks? From their website React is a JavaScript library for building user interfaces. React makes it painless to create interactive UIs and also build encapsulated components that manage their own state then compose them to make interactive UIs.</p><p>Hooks are the new feature introduced in the React 16.8 version. It <strong>allows you to use state and other React features without writing a class</strong>. Hooks are the functions which “hook into” React state and life-cycle features from function components. It does not work inside classes.</p><p>So, on to my favorite hook, <a href="https://www.npmjs.com/package/use-local-storage"><em>useLocalStorage</em></a><em>. To install it, go to the root of your project, open the terminal and run:</em></p><pre><em>npm i use-local-storage</em></pre><p>In the file you want to use it in e.g Dashboard.js, import it like this:</p><pre>import useLocalStorage from <em>“use-local-storage”</em>;</pre><p>Go to your CSS folder and write these CSS rules:</p><pre>:root{</pre><pre> — background: white;</pre><pre> — text-primary:black;</pre><pre>}</pre><pre>[data-theme=<em>’dark’</em>]{</pre><pre> — background: black;</pre><pre> — text-primary:white;</pre><pre>}</pre><p>To use our colors we will write something like:</p><pre>body {</pre><pre>color: var( — text-primary);</pre><pre>background: var(— background);</pre><pre>}</pre><p>This will choose between the black and white colors we wrote earlier.</p><p>Back to Dashboard.js we can set our theme using the useLocalStorage hook like this:</p><pre>function Dashboard() {</pre><pre>//...more code</pre><pre>const [theme, setTheme] = useLocalStorage(<em>“theme”</em> ? <em>“dark”</em> : <em>“light”</em>);</pre><pre>const switchTheme = () =&gt; {</pre><pre>const newTheme = theme === <em>“light”</em> ? <em>“dark”</em> : <em>“light”</em>;</pre><pre>setTheme(newTheme);</pre><pre>//..more code</pre><pre>};</pre><p>Using the ternary operator we use useLocalStorage to set our theme. If the theme is light, switch it to dark theme and if the opposite is true, switch to light theme.</p><pre>function Dashboard() {</pre><pre>//...more code</pre><pre> return (<br>     &lt;div data-theme={theme}.....&gt;<br>          &lt;div&gt;</pre><pre>     the webpage</pre><pre>          &lt;/div&gt;</pre><pre>     &lt;/div&gt;</pre><pre>};</pre><p>Now all we need is to call our switchTheme() function. And what better way to change themes than using an onClick function on a button.</p><pre>&lt;button id=<em>”btn” </em>onClick={switchTheme}&gt;Change Theme&lt;/button&gt;</pre><p>And on button click voila, light theme, dark theme…or just stay in the dark theme forever.</p><p>Adding it into our React Film Friday’s app and we get something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HbJJQArUCUhXqb0EIBjy7A.png" /><figcaption>Our web application with Light Theme on.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HCCLaMQOiT5lc6nL7ugVxw.png" /><figcaption>Our web application with dark theme on.</figcaption></figure><p>So you might ask, why use the useLocalStorage hook and not useState? With useLocalStorage hook we can refresh our web application as many times as we need, we can go back to our web application in three days and the web application will “remember” which theme we chose.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bc30a578c8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Project Using An API]]></title>
            <link>https://machariamwai.medium.com/my-first-project-using-an-api-39565a0490df?source=rss-d04eebbdb2a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/39565a0490df</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[tmdb]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mwai]]></dc:creator>
            <pubDate>Thu, 21 Apr 2022 17:59:34 GMT</pubDate>
            <atom:updated>2022-04-21T17:59:34.005Z</atom:updated>
            <content:encoded><![CDATA[<p>I know you have heard of the ‘word’ <strong><em>API</em></strong> but do you know what it means? I had heard of the acronym API several times but never really bothered to find out what it means. If you are just like me then let me help you. API stands for Application Programming Interface which is <a href="https://www.redhat.com/en/topics/api/what-are-application-programming-interfaces#:~:text=API%20stands%20for%20application%20programming,building%20and%20integrating%20application%20software.">a set of definitions and protocols for building and intergrating application software.</a></p><p>Okay…woah what does that all mean? To simplify it, imagine you are in a restaurant, the menu tells you what they (most probably) have in the kitchen. Let’s say you want egg fried rice. Extra vegetables so you can stay healthy. The waiter comes along and you give him your order. The waiter goes to the kitchen and relays your order to the chef, who then plates the food and the waiter is back with your meal. In this scenario, the waiter is our API. The customer/user (us) do not need to know how or when the food was prepared as long as it is fresh and exactly what we ordered. If the food is not what we ordered, we can ask the waiter to change the order.</p><p>APIs work in almost the same way as the waiter. They receive a set of instructions, relay the instructions to the back-end and/or database, fetch the requested data and return a response to the source of the request. If the data returned is not correct or unavailable we can try to change the parameters of our request.</p><p>I decided that my first project using an API would involve one other thing that I love more than food, movies. Using the <a href="https://www.themoviedb.org/documentation/api">The Movie Database API</a> I decided to build a web application that displays the current most popular movie posters together with the movie blurb and using a search bar the user can search for a movie using the title and get almost similar results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pVTGGrNiQiIQ5C7nVB6aSg.png" /><figcaption>My function to fetch data from the TMDB API</figcaption></figure><p>I used this function with the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch API </a>to get data from TMDB. The Fetch API could take an entire webpage of it’s own to go through but in our case we have a function that fetches data from a certain URL. Our URL in this case holds a JSON file for the 20 most popular movies at the time the data is fetched and sent back. We would then display the data in the console if we undid the comment but for now we have another function<strong> showMovies( )</strong> that will display the data we get back on our DOM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ILbq7jRH4BA7RjfcxrMtdQ.png" /><figcaption>Our function that displays data to the DOM.</figcaption></figure><p>Having fetched the data we can now display it on our Document Object Model also known as DOM. We pass the data we got from the TMDB API to our function as an argument.</p><p>We then create an object “movie” that contains a title, poster path(image), and overview(blurb). We create a new div dynamically and give it the name “movieElement”. On the movieElement we then add a class name “movie” and also add a few more elements to the innerHTML of the div. (Also be sure to check out the difference between innerHTML, textContents and innerText. We can then append our movieElement to the main section of our website. The main section had been already created in our HTML.</p><p>So what does our website look like with a bit of CSS after consuming the TMDB API? Here have a look…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpB0iQXkxjHJKXURlq0CBw.png" /><figcaption>Screenshot of the website on<a href="https://mwaidesu.github.io/film-fridays/"> Github Pages</a></figcaption></figure><p>Here is the <a href="https://github.com/mwaidesu/film-fridays">Github Repo</a>.</p><p>Here is the <a href="https://mwaidesu.github.io/film-fridays/">Github Pages Live Link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39565a0490df" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>