<?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 Ahmed Shehata on Medium]]></title>
        <description><![CDATA[Stories by Ahmed Shehata on Medium]]></description>
        <link>https://medium.com/@ahmed_shehata?source=rss-15801ffeb1b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jID5_deSETYDcvYMHuWtkQ.jpeg</url>
            <title>Stories by Ahmed Shehata on Medium</title>
            <link>https://medium.com/@ahmed_shehata?source=rss-15801ffeb1b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:18:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmed_shehata/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[Flutter for Android Developers — Flutter Community — Part 5]]></title>
            <link>https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-community-part-5-bb27e552291b?source=rss-15801ffeb1b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb27e552291b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Ahmed Shehata]]></dc:creator>
            <pubDate>Fri, 22 Mar 2024 13:56:23 GMT</pubDate>
            <atom:updated>2024-03-22T13:56:23.382Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter for Android Developers — Flutter Community — Part 5</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rMMXtoyjD44yZuZF" /><figcaption>Photo by <a href="https://unsplash.com/@jupp?utm_source=medium&amp;utm_medium=referral">Jonathan Kemper</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Reminder</p><p>These are a series of articles for Android Developers to learn Flutter if you missed them:</p><ul><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-fully-guide-to-learning-flutter-da541c03c7e9">Part 1 — Dart VS Kotlin</a></li><li><a href="https://medium.com/@ahmed_shehata/part-2-flutter-for-android-developers-widgets-vs-compose-875a07c09358">Part 2 — Widgets VS Compose</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-stateful-widget-vs-compose-states-part-3-0ab52f0a2ac9">Part 3 — Stateful Widget VS Compose states</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-libs-vs-android-libs-part-4-a68d3dbd3ed4">Part 4 — Flutter libs VS Android libs</a></li><li>Part 5 — Flutter Community ← (We’re here)</li></ul><h3>Some Topics I never talked about</h3><ul><li><a href="https://docs.flutter.dev/testing/overview">Testing</a></li><li><a href="https://pub.dev/packages/flutter_localization">Localization</a></li><li>Dependency injection (<a href="https://pub.dev/packages/get_it">get_it</a>)</li><li><a href="https://docs.flutter.dev/platform-integration/platform-channels">Platforms Channel</a> (To write native code)</li></ul><h3>Are we Done?</h3><blockquote>“Remember, learning is not a one-time step; it’s an ongoing journey. Stay updated and continuously strive for knowledge to thrive in the ever-evolving landscape of technology.”</blockquote><h3>Being up to date</h3><blockquote>“Staying up to date is crucial in the fast-paced world of technology, where advancements occur rapidly. Keep learning and adapting to stay ahead of the curve.”</blockquote><p><a href="https://medium.com/flutter-community">Flutter Community</a></p><p><a href="https://www.youtube.com/resocoder">Reso Coder</a></p><p><a href="https://www.youtube.com/c/JohannesMilke/videos">HeyFlutter</a></p><p><a href="https://www.youtube.com/hellocodepur">Codepur</a></p><p><a href="https://www.youtube.com/c/FlutterMapp">Flutter Mapp</a></p><h3>You can save your time and just Follow me 😌</h3><p><a href="https://linktr.ee/ahmed_shehataa">Linktree</a>(LinkedIn —GitHub — Twitter)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb27e552291b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter for Android Developers — Flutter libs VS Android libs — Part 4]]></title>
            <link>https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-libs-vs-android-libs-part-4-a68d3dbd3ed4?source=rss-15801ffeb1b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a68d3dbd3ed4</guid>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[retrofit]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ahmed Shehata]]></dc:creator>
            <pubDate>Fri, 22 Mar 2024 13:27:19 GMT</pubDate>
            <atom:updated>2024-03-22T14:02:03.091Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter for Android Developers — Flutter libs VS Android libs — Part 4</h3><p>Reminder</p><p>These are a series of articles for Android Developers to learn Flutter if you missed them:</p><ul><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-fully-guide-to-learning-flutter-da541c03c7e9">Part 1 — Dart VS Kotlin</a></li><li><a href="https://medium.com/@ahmed_shehata/part-2-flutter-for-android-developers-widgets-vs-compose-875a07c09358">Part 2 — Widgets VS Compose</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-stateful-widget-vs-compose-states-part-3-0ab52f0a2ac9">Part 3 — Stateful Widget VS Compose states</a></li><li>Part 4 — Flutter libs VS Android libs ← (We’re here)</li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-community-part-5-bb27e552291b">Part 5 — Flutter Community</a></li></ul><h3>We‘ll discuss here the alternatives of Android Topics/Libraries in Flutter</h3><h4>Threading</h4><ul><li>In Android → Coroutines/ RxJava / ExecutorService</li></ul><pre>// Coroutines<br>class MainActivity : AppCompatActivity() {<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br><br>        // 2 - Call it within Coroutine scope<br>        lifecyclescope.launch(Dispatchers.IO) {<br>            val users = getUsers()<br>        }<br>    }<br><br>// 1- Define your suspend fun<br>suspend fun getUsers(): List&lt;Users&gt; {<br>    return getUsersFromNetwork()<br>}<br>}</pre><ul><li>In Flutter → async &amp; await 😎(Easyyyyy)</li></ul><pre>@override<br>  Widget build(BuildContext context) {<br>  // 2- Call and Await your method<br>  var users = await getUsers();<br>  //....<br>}<br><br>// 1- Define a method that returns your response wrapped with Future <br>// and mark it as async<br>Future&lt;List&lt;User&gt;&gt; getUsers() async {<br>     return getUsersFromNetwork();<br>}</pre><blockquote>Remember: Dart has a <strong>single-threaded</strong> execution model (<a href="https://dart.dev/codelabs/async-await">Learn more</a>)</blockquote><h4>Navigation</h4><ul><li>In Android(Compose) → Compose navigation/ Voyager /compose-destinations</li></ul><pre>// Compose navigation<br>@Composable<br>fun MyButton() {<br>  Button(<br>    onClick = { navController.navigate(&quot;secondScreen&quot;) }<br>  ) {<br>    Text(text = &quot;Go to Second Screen&quot;)<br>  }<br>}</pre><ul><li>In Flutter → Navigator / <a href="https://pub.dev/packages/go_router">go_router</a></li></ul><pre>// Navigator<br>@override<br>  Widget build(BuildContext context) {<br>    return ElevatedButton(<br>    onPressed: () {<br>      Navigator.push(context,<br>         MaterialPageRoute(builder: (context) =&gt; SecondRoute()),<br>     );<br>    },<br>    child: Text(&#39;Go to Second Screen&#39;),<br>    );<br>}</pre><h4>Networking</h4><ul><li>In Android → Retrofit (You know it) 😆</li><li>In Flutter → <a href="https://pub.dev/packages/dio">Dio</a></li></ul><pre>Future&lt;void&gt; fetchData() async {<br>  try {<br>    // You can add more setup like adding headers - interceptors - basic setup ..etc<br>    Dio dio = Dio();<br>    Response response = await dio.get(&#39;https://api.example.com/endpoint&#39;);<br>    if (response.statusCode == 200) {<br>      // Successful response<br>      print(response.data);<br>    } else {<br>      // Handle error<br>    }<br>  } catch (e) {<br>    // Handle failure<br>    print(e.toString());<br>  }<br>}</pre><h4>Image Loading</h4><ul><li>In Android → Coil/Picasso/Glide</li></ul><pre>AsyncImage(<br>    model = ImageRequest.Builder(LocalContext.current)<br>        .data(&quot;https://example.com/image.jpg&quot;)<br>        .build(),<br>    placeholder = painterResource(R.drawable.placeholder),<br>    contentDescription = stringResource(R.string.description),<br>    contentScale = ContentScale.Crop,<br>)</pre><ul><li>In Flutter → <a href="https://pub.dev/packages/cached_network_image">cached_network_image</a></li></ul><pre>CachedNetworkImage(<br>    imageUrl: &#39;https://example.com/image.jpg&#39;,<br>    placeholder: (context, url) =&gt; CircularProgressIndicator(),<br>    errorWidget: (context, url, error) =&gt; Icon(Icons.error),<br>);</pre><h4>Local DB (SQL)</h4><ul><li>In Android → Room/SQLite</li><li>In Flutter → <a href="https://pub.dev/packages/sqflite">sqflite</a></li></ul><h4>Local DB (NOSQL)</h4><ul><li>In Android → Realme</li><li>In Flutter → <a href="https://pub.dev/packages/hive">Hive</a></li></ul><h4>Local DB (Key-Value pair)</h4><ul><li>In Android → DataStore/Shared Preference</li><li>In Flutter → <a href="https://pub.dev/packages/shared_preferences">shared_preference</a></li></ul><h4>Pagination</h4><ul><li>In Android → Paging3</li><li>In Flutter → <a href="https://pub.dev/packages/infinite_scroll_pagination">infinite_scroll_pagination</a> or <em>Create your one like me</em></li></ul><h3>So the question is...</h3><h3>How have I learned all of these topics and more within a few weeks ? 😋</h3><blockquote>Flutter for Android developers</blockquote><p>This doc helped me a lot to discover and compare both Android and Flutter <a href="https://docs.flutter.dev/get-started/flutter-for/android-devs">Check it </a>👈</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/174/1*JWNNImKRdgdQHrJwcouhfA.png" /><figcaption><a href="https://docs.flutter.dev/get-started/flutter-for/android-devs#fixed-sidenav-1-6">From another platform?</a></figcaption></figure><blockquote>Write and Apply</blockquote><p>Create Your First Flutter Project to apply topics(Advanced — Basics) as much you can which you know from <strong>Android</strong> into <strong>Flutter</strong>(Clean arch-Notifications-Channels-Pagination-DI-Testing-Flavors ..etc).</p><blockquote>Searching is the key</blockquote><p>Keep searching for every single new challenge or topic using Google, ChatGPT, or Gemini (any useful AI tool).</p><blockquote>Get a help</blockquote><p>In the beginning, you may suffer from learning new things and facing some errors so at this point you can get help from a friend you know.</p><blockquote>I have created my first Flutter Project and tried to apply as much as possible to discover Flutter</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*oBqXzQaVMs0DPqjS4HC1ng.png" /></figure><ul><li>Clean arch</li><li>Bloc for state management</li><li>Custom Pagination</li><li>Cashing (sqflite)</li><li>Shard_preference</li><li>Light/Dark theme</li><li>Localization</li></ul><p><a href="https://github.com/ahmed-shehataa/Morty-Flutter">GitHub - ahmed-shehataa/Morty-Flutter</a></p><p>Resources 📘</p><ul><li><a href="https://docs.flutter.dev/get-started/flutter-for/android-devs">Flutter for Android developers</a></li><li><a href="https://dart.dev/codelabs/async-await">Asynchronous programming: futures, async, await</a></li></ul><p>Next Article 📑</p><p><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-community-part-5-bb27e552291b">Part 5 — Flutter Community</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a68d3dbd3ed4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter for Android Developers — Stateful Widget VS Compose States — Part 3]]></title>
            <link>https://medium.com/@ahmed_shehata/flutter-for-android-developers-stateful-widget-vs-compose-states-part-3-0ab52f0a2ac9?source=rss-15801ffeb1b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ab52f0a2ac9</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[compose]]></category>
            <dc:creator><![CDATA[Ahmed Shehata]]></dc:creator>
            <pubDate>Sat, 09 Mar 2024 12:30:34 GMT</pubDate>
            <atom:updated>2024-03-22T14:20:11.024Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter for Android Developers — Stateful Widget VS Compose States — Part 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*EHaoiTk3LCkBWMo0.png" /></figure><p>Reminder</p><p>These are a series of articles for Android Developers to learn Flutter if you missed them:</p><ul><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-fully-guide-to-learning-flutter-da541c03c7e9">Part 1 — Dart VS Kotlin</a></li><li><a href="https://medium.com/@ahmed_shehata/part-2-flutter-for-android-developers-widgets-vs-compose-875a07c09358">Part 2 — Widgets VS Compose</a></li><li>Part 3 — Stateful Widget VS Compose states ← (We’re here)</li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-libs-vs-android-libs-part-4-a68d3dbd3ed4">Part 4 — Flutter libs VS Android libs</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-community-part-5-bb27e552291b">Part 5 — Flutter Community</a></li></ul><blockquote>Any declarative UI needs a state to rebuild the UI again when data changes.</blockquote><h4>In Compose:</h4><p>States are represented by the mutableStateOf() and state objects and we need to remember them into the memory.</p><h4>In Flutter:</h4><p>We need to use a <strong>Stateful Widget</strong> which has a mutable State and when the state changes the widget tree is rebuilt to reflect the changes.</p><p>Let’s Dive into coding</p><p>We‘ll Build a simple screen that has two buttons and text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*S5ggjsM3BJtHrcrRuVmsFw.png" /></figure><h4>In Compose:</h4><pre>@Composable<br>@Preview(showBackground = true, showSystemUi = true, backgroundColor = 0XFFFFFF)<br>fun Screen() {<br>    Column {<br>        var counter by remember {<br>            mutableStateOf(0)<br>        }<br>        ButtonCounter(title = &quot;UP&quot;, onClick = {<br>            counter++<br>        })<br><br>        ButtonCounter(title = &quot;Down&quot;, onClick = {<br>            counter--<br>        })<br><br>        TextCounter(counter = counter)<br>    }<br>}<br><br>@Composable<br>fun TextCounter(counter: Int) {<br>    Text(text = &quot;Counter: $counter&quot;)<br>}<br><br>@Composable<br>fun ButtonCounter(title: String, onClick: () -&gt; Unit) {<br>    Button(onClick = onClick) {<br>        Text(text = title)<br>    }<br>}</pre><h4>In Compose — Stateful VS stateless:</h4><p><strong>1 — Screen</strong> composable is <em>stateful</em> but why?</p><blockquote>A composable that uses remember to store an object creates an internal state, making the composable <em>stateful</em></blockquote><p><strong>2 — ButtonCounter</strong> and <strong>TextCounter </strong>both are<strong> </strong><em>stateless.</em></p><blockquote>A <em>stateless</em> composable is a composable that doesn’t hold any state.</blockquote><p>3 — <a href="https://developer.android.com/jetpack/compose/state#state-hoisting"><strong>State hoisting</strong></a></p><blockquote>State hoisting in Compose is a pattern of moving state to a composable’s caller to make a composable stateless.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*m6f7hYBLBgZVAfF_Ard7cw.png" /><figcaption>Compose State hoisting</figcaption></figure><blockquote>You noticed that we try our best to make our composables stateless as we can (same in Flutter)</blockquote><h4>In Flutter:</h4><pre>class ButtonCounter extends StatelessWidget {<br>  final String title;<br>  final VoidCallback onPressed;<br><br>  const ButtonCounter({<br>    required this.title,<br>    required this.onPressed,<br>  });<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return ElevatedButton(<br>      onPressed: onPressed,<br>      child: Text(title),<br>    );<br>  }<br>}</pre><pre>class TextCounter extends StatelessWidget {<br>  final int counter;<br><br>  const TextCounter({required this.counter});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Text(&#39;Counter: $counter&#39;);<br>  }<br>}</pre><p>To create a stateful widget to wrap all previous, just write <strong>stf </strong>and press enter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*T-nXk49z7oVavG5cgulLNw.png" /></figure><pre>class Screen extends StatefulWidget {<br><br>  @override<br>  _ScreenState createState() =&gt; _ScreenState();<br>}<br><br>class _ScreenState extends State&lt;Screen&gt; {<br>  int _counter = 0;<br><br>  void _incrementCounter() {<br>    setState(() {<br>      _counter++;<br>    });<br>  }<br><br>  void _decrementCounter() {<br>    setState(() {<br>      _counter--;<br>    });<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      body: Column(<br>        children: [<br>          ButtonCounter(<br>            title: &#39;UP&#39;,<br>            onPressed: _incrementCounter,<br>          ),<br>          ButtonCounter(<br>            title: &#39;Down&#39;,<br>            onPressed: _decrementCounter,<br>          ),<br>          TextCounter(counter: _counter),<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><h4>Some Notes:</h4><ul><li><em>incrementCounter, decrementCounter, and counter</em> are <strong>private</strong> fields.</li><li>You <strong>must</strong> call <strong><em>setState</em></strong><em>(() { }) to rebuild the UI again after changing counter</em> variable.</li><li>Why const before the constructor call ?</li></ul><blockquote><strong>Constant Constructor</strong> is used to create a object whose value cannot be changed. It Improves the performance of the program. (<a href="https://dart-tutorial.com/object-oriented-programming/constant-constructor-in-dart/">read more</a>)</blockquote><h3>State-Management in Flutter</h3><p>Using the <strong><em>setState </em></strong>is not the only way to rebuild the UI and manage states in Flutter, here are some of the packages to do the same and more efficiently:</p><p>1 — Provider</p><p>2 — Bloc (It is similar to MVI in Android)</p><p>3 — GetX</p><p>4 — Riverpod</p><p>5 — Redux</p><blockquote>Resources:</blockquote><ul><li><a href="https://docs.flutter.dev/data-and-backend/state-mgmt/options#redux">List of state management approaches</a> (<strong>Read</strong> this first to learn more) 👈</li><li><a href="https://medium.com/flutter-community/flutter-bloc-for-beginners-839e22adb9f5">Flutter bloc for beginners</a></li><li><a href="https://medium.com/flutter-community/flutter-bloc-concurrency-simplified-6348ec4c2510">Flutter Bloc Concurrency — Simplified</a></li><li><a href="https://nureddineraslan.medium.com/understanding-state-management-with-provider-in-flut-e74e0b9e49d9">Understanding state management with Provider in Flutter</a></li></ul><h3>PUB dev is your new home</h3><p>The official package repository for <a href="https://dart.dev/">Dart</a> and <a href="https://flutter.dev/">Flutter</a> apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*DRvtFw92VZxJ5oDN7edIqQ.png" /></figure><p>is contains a lot of packages (libraries) to build a flutter project faster and easier.</p><h4>Most of the famous ones:</h4><ul><li>shared_preferences</li><li>flutter_svg</li><li>get_it</li><li>dio</li><li>flutter_bloc</li></ul><h4>How to install any package into your app?</h4><p>1 — <strong>Open</strong> the package page -&gt; Then press the <strong>Installing</strong> tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*X84M2MUnWEdNzv5tGtUSeA.png" /></figure><p>2 — <strong>Open</strong> Android studio terminal and write then press enter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*apjt2WdJOw4Y61B21bqQyg.png" /></figure><p>3 — Now you can <strong>find</strong> it in your <em>pubspec.yaml</em></p><blockquote>The pubspec file specifies dependencies that the project requires, such as particular packages (and their versions), fonts, or image files.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*kh2xv73m2Mkl58UP-5vrEg.png" /><figcaption><em>pubspec.yaml</em></figcaption></figure><h3><strong>Resources</strong></h3><p>Adding resources to your project like (images, fonts, gifs, strings..etc)</p><h4>In Compose:</h4><ul><li>Just add them under <em>res</em> folder</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*f_yHu48LW8swNyArzX2RoA.png" /></figure><h4>In Flutter:</h4><p>1 — Create an <strong>assets</strong> folder at root of your project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*FF6NlB3-jcE6C54ZNgG5dg.png" /></figure><blockquote>You can customize and add many directories to the assets folder as you see</blockquote><p>2 — Open <strong><em>pubspec.yaml</em></strong> under <strong><em>flutter:</em></strong> → add all your assets dir</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*UqXnjVQAMWso9EYGhgyjYg.png" /></figure><h3>Theming</h3><p>Theming is a really important topic for mobile development, for easily sharing colors, typo, shapes, and more across your entire app.</p><h3>Colors</h3><h4>In Compose:</h4><pre>val LightColorPalette = lightColors(<br>    primary = Color(0xFF6200EE),<br>    primaryVariant = Color(0xFF3700B3),<br>    secondary = Color(0xFF03DAC5),<br>    // more<br>)<br><br>val DarkColorPalette = lightColors(<br>    primary = Color(0xFF6200EE),<br>    primaryVariant = Color(0xFF3700B3),<br>    secondary = Color(0xFF03DAC5),<br>    // more<br>)</pre><h4>In Flutter:</h4><pre>const lightColors = ColorScheme(<br>  brightness: Brightness.light,<br>  primary: Color(0xFF004F98),<br>  onPrimary: Color(0xFF004F98),<br>  secondary: Color(0xFF03DAC5),<br>  // more<br>);<br><br>const darkColors = ColorScheme(<br>  brightness: Brightness.dark,<br>  primary: Color(0xFF007ff5),<br>  onPrimary: Color(0xFFFFFFFF),<br>  secondary: Color(0xFFBBBBBB),<br>  // more<br>);</pre><h3>Typo</h3><h4>In Compose:</h4><pre>val Typography = Typography(<br>    subtitle1 = TextStyle(<br>        fontFamily = FontFamily.Default,<br>        fontWeight = FontWeight.Bold,<br>        fontSize = 22.sp<br>    ),<br>    subtitle2 = TextStyle(<br>        fontFamily = FontFamily.Default,<br>        fontWeight = FontWeight.Normal,<br>        fontSize = 16.sp<br>    ),<br>    // add more<br>)</pre><h4>In Flutter:</h4><pre>TextTheme getTextTheme(BuildContext context) {<br>  return TextTheme(<br>    bodySmall: TextStyle(<br>        color: Theme.of(context).colorScheme.primary,<br>        fontSize: 14,<br>        fontWeight: FontWeight.normal),<br>    bodyMedium: TextStyle(<br>        color: Theme.of(context).colorScheme.primary,<br>        fontSize: 16,<br>        fontWeight: FontWeight.normal),<br>    // add more<br>  );<br>}</pre><h3>Finally 👏</h3><blockquote>wrap your starter composable with AppTheme</blockquote><h4>In Compose:</h4><pre>@Composable<br>fun AppTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -&gt; Unit) {<br>    MaterialTheme(<br>        colors = if (darkTheme) DarkColorPalette else LightColorPalette,<br>        typography = Typography,<br>        shapes = Shapes,<br>        content = content<br>    )<br>}</pre><pre>class HomeActivity : ComponentActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        enableEdgeToEdge()<br>        super.onCreate(savedInstanceState)<br>        <br>        setContent {<br>            // here<br>            AppTheme {<br>                SplashScreen()<br>            }<br>        }<br>    }<br>}</pre><h4>In Flutter:</h4><blockquote>wrap your starter widget with MaterialApp</blockquote><pre>ThemeData getThemeData({required BuildContext context, bool isDark = false}) {<br>  return ThemeData(<br>    useMaterial3: true,<br>    fontFamily: GoogleFonts.lato().fontFamily,<br>    textTheme: getTextTheme(context),<br>    colorScheme: isDark ? darkColors : lightColors,<br>    // ...etc<br>  );<br>}</pre><pre>@override<br>  Widget build(BuildContext context) {<br>    // here<br>    return MaterialApp(<br>      debugShowCheckedModeBanner: false,<br>      theme: getThemeData(context: context),<br>      darkTheme: getThemeData(context: context, isDark: true),<br>      home: const SplashScreen(),<br>    );<br>  }</pre><blockquote>You can find all of this code uploaded into this repo → <a href="https://github.com/ahmed-shehataa/Morty-Flutter/tree/master/lib/theme">Morty</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/194/1*x09Y0_nFdOBkVC_gWZaU8Q.png" /><figcaption>Theme</figcaption></figure><h4>Important notes 📕</h4><ul><li>Adding or removing spaces in <em>pubspec.yaml </em>can indeed affect the structure and interpretation of the file.</li><li>To display an SVG in Flutter use this package → <a href="https://pub.dev/packages/flutter_svg">flutter_svg</a></li></ul><p>Next Article 📑</p><p><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-libs-vs-android-libs-part-4-a68d3dbd3ed4">Part 4 — Flutter libs VS Android libs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ab52f0a2ac9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter for Android Developers —Widgets VS Compose — Part 2]]></title>
            <link>https://medium.com/@ahmed_shehata/part-2-flutter-for-android-developers-widgets-vs-compose-875a07c09358?source=rss-15801ffeb1b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/875a07c09358</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ahmed Shehata]]></dc:creator>
            <pubDate>Sat, 24 Feb 2024 12:32:15 GMT</pubDate>
            <atom:updated>2024-03-22T14:01:06.375Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter for Android Developers —Widgets VS Compose — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WXQHPGGMnMRHjMVP" /></figure><p>Reminder</p><p>These are a series of articles for Android Developers to learn Flutter if you missed them:</p><ul><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-fully-guide-to-learning-flutter-da541c03c7e9">Part 1 — Dart VS Kotlin</a></li><li>Part 2 — Widgets VS Compose. ← (We’re here)</li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-stateful-widget-vs-compose-states-part-3-0ab52f0a2ac9">Part 3 — Stateful Widget VS Compose states</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-libs-vs-android-libs-part-4-a68d3dbd3ed4">Part 4 — Flutter libs VS Android libs</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-community-part-5-bb27e552291b">Part 5 — Flutter Community</a></li></ul><p>Let’s GOoO</p><blockquote>Everything in Flutter could be a Widget</blockquote><p><strong>Widgets: </strong>Each element on a screen of the Flutter app is a widget(Class).</p><p><strong>Composable</strong>: is a piece of reusable code (Method).</p><h3>Widgets have two types:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*J_NH1tWIrBledl3F.png" /></figure><p><strong>Stateless:</strong> are those components that describe a part of the user interface that can be determined <strong>only by configurations in the constructor</strong></p><p><strong>Stateful:</strong> are those that can change their state over time. (using states)</p><h3>Let’s create our first Stateless widget</h3><p><strong>Go</strong> to Lib → Right Click → New → Dart File</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*iZ-bcaMRwuSWaL_NWZDNMg.png" /></figure><p><strong>Write</strong> “st”, and then Android Studio will give you some predefined templates (Stateless — Stateful)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*tGDF1EoOwOToWOBB5G7_WA.png" /></figure><p><strong>Write</strong> Alt + Enter (Windows or Linux) to import</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*4yMNh8BvsMdOnBAQT23g2w.png" /></figure><p><strong>Final</strong> code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*73b6JmmoGHAowS68DheOLA.png" /></figure><blockquote>The build method is just a fun that takes a context and returns a widget</blockquote><blockquote>Override it to write any Widgets there.</blockquote><h3>Some Widgets that we will need:</h3><ul><li>Scaffold</li><li>AppBar</li><li>Column — Row</li><li>Container</li><li>Padding</li><li>Image</li><li>Stack</li><li>Text</li><li>Button</li></ul><p><strong>Check</strong> out this <a href="https://docs.flutter.dev/ui/widgets">Widget catalog</a> to see all available widgets there:</p><h3>Compose VS Widgets</h3><h4>Entry Point to your app</h4><p>In Android, you need at least <strong>one activity</strong> to host your <strong>composables</strong> within</p><p>In Flutter, you need just to run the main method and call <strong>runApp</strong> which takes an instance from our <strong>starter widget(MyApp)</strong>.</p><pre>// Android<br>class HomeActivity : ComponentActivity() {<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContent {<br>            MaterialTheme(<br>              colors = // ...<br>              typography = // ...<br>              shapes = // ...<br>            ) {<br>                MyHomePage()<br>            }<br>        }<br>    }<br>}</pre><pre>// Flutter <br>void main() {<br>  runApp(const MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Flutter Demo&#39;,<br>      theme: ThemeData(<br>        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),<br>        useMaterial3: true,<br>      ),<br>      home: const MyHomePage(title: &#39;Flutter Demo Home Page&#39;),<br>    );<br>  }<br>}</pre><h4>Some Notes</h4><ul><li>In compose we wrap <strong>MyHomePage</strong> within <strong>MaterialTheme.</strong></li><li>In Flutter we wrap <strong>MyHomePage</strong> within <strong>MaterialApp.</strong></li><li><strong>MaterialTheme &amp; MaterialApp</strong>: Provide color, typography, and shape attributes for all composables/widgets.</li><li>In compose: To enable Material 3: Use <a href="https://developer.android.com/jetpack/compose/designsystems/material3"><strong>MaterialTheme form M3.</strong></a></li><li>In Flutter: To enable Material 3: Set useMaterial3<strong> = true.</strong></li></ul><h4>1 — Text</h4><p>color — fontSize — fontWeight — maxLines — overflow …etc</p><pre>// Compose<br>@Composable<br>fun MyText() {<br>    Text(<br>        text = &quot;Hello&quot;,<br>        style = TextStyle().copy(<br>            color = Color.Black,<br>            fontSize = 16.sp,<br>            fontWeight = FontWeight.Bold,<br>        ),<br>        maxLines = 1,<br>        overflow = TextOverflow.Ellipsis,<br>    )<br>}</pre><pre>// Widget<br> @override<br>  Widget build(BuildContext context) {<br>     return Text(<br>      &#39;Hello&#39;,<br>      style: TextStyle(<br>        color: Colors.black,<br>        fontSize: 16,<br>        fontWeight: FontWeight.bold,<br>      ),<br>      maxLines: 1,<br>      overflow: TextOverflow.ellipsis,<br>    );<br>  }</pre><blockquote>You See 👀 → there is no big difference between both</blockquote><h4>2 — Button</h4><p>onClick — shape — content — border ..etc</p><pre>// Compose<br>@Composable<br>fun MyButton() {<br>    Button(<br>        enabled = true,<br>        shape = RoundedCornerShape(50),<br>        border = BorderStroke(width = 1.dp, color = Color.Black),<br>        onClick = {<br><br>        },<br>        content = {<br>            Text(text = &quot;Click ME!&quot;)<br>        }<br>    )<br>}</pre><pre>// Widget<br> @override<br>  Widget build(BuildContext context) {<br>    return ElevatedButton(<br>      style: ButtonStyle(<br>        shape: MaterialStateProperty.all&lt;RoundedRectangleBorder&gt;(<br>          RoundedRectangleBorder(<br>            borderRadius: BorderRadius.circular(50.0),<br>            side: BorderSide(color: Colors.black, width: 1.0),<br>          ),<br>        ),<br>      ),<br>      onPressed: () {<br>      <br>      },<br>      onLongPress: () {<br>        <br>      },<br>      child: Text(&#39;Click ME!&#39;),<br>    );<br>  }</pre><h4>Some Notes</h4><ul><li>Flutter has <strong>no Button </strong>widget but has <a href="https://genotechies.medium.com/flutter-button-types-and-what-are-the-deprecated-button-types-and-how-to-replace-them-c8506b8c398a">many other types</a> (ElevatedButton — OutlinedButton — TextButton — IconButton).</li><li>To make ElevatedButton <strong>disabled</strong> just pass null to onPressed.</li></ul><h4>3 — Column</h4><blockquote><strong>Row</strong> is the same Concept</blockquote><pre>// Compose<br>@Composable<br>fun Screen() {<br>    Column(<br>        verticalArrangement = Arrangement.spacedBy(12.dp),  <br>        horizontalAlignment = Alignment.CenterHorizontally<br>    ) {<br>        Text(text = &quot;1&quot;)<br>        Text(text = &quot;2&quot;)<br>        Text(text = &quot;3&quot;)<br>    }<br>}</pre><pre>// Widget<br> @override<br>  Widget build(BuildContext context) {<br>    return Column(<br>      mainAxisAlignment: MainAxisAlignment.start,<br>      crossAxisAlignment: CrossAxisAlignment.center,<br>      children: [<br>        Text(&#39;1&#39;),<br>        SizedBox(height: 12),<br>        Text(&#39;2&#39;),<br>        SizedBox(height: 12),<br>        Text(&#39;3&#39;),<br>      ],<br>    );<br>  }</pre><h4>Some Notes</h4><ul><li>In Flutter, widgets (column and row) take an array of <strong>children</strong>.</li><li>There is no <strong>spacedBy</strong> in Flutter, you can use the SizedBox widget to add spaces.</li><li><a href="https://medium.com/huawei-developers/flutter-vs-jetpack-compose-comparison-learning-series-part-1-98f60a5f68c6">Check this great article </a>(to see the main diff between column and row alignments) by <a href="https://medium.com/u/2f2ba4548999">Emre Ugur Yalcin</a>.</li></ul><h4>4 — Box</h4><pre>// compose<br>@Composable<br>fun Greeting() {<br>    Box(Modifier.fillMaxSize()) {<br>        Text(<br>            text = &quot;Hello&quot;,<br>            modifier = Modifier.align(Alignment.TopStart)<br>        )<br><br>        Text(<br>            text = &quot;Hello again&quot;,<br>            modifier = Modifier.align(Alignment.TopEnd)<br>        )<br>        <br>        //...<br>    }<br>}</pre><pre>// widgets<br><br>return Stack(<br>      children: [<br>        Align(<br>         alignment: Alignment.topLeft,<br>          child: Text(&quot;Hello&quot;),<br>        ),<br>        Align(<br>          alignment: Alignment.topRight,<br>          child: Text(&quot;Hello again&quot;),<br>        ),<br>  <br>      ],<br>    );<br>  }</pre><h4>Some Notes:</h4><ul><li>In Flutter we use <strong>Stack </strong><em>(same as Box in compose)</em>.</li><li><strong>Stack</strong> takes (array of children widgets) → which could be <strong>Align</strong> or <strong>Positioned</strong>.</li></ul><h4>5 — Modifiers</h4><p>For sorry there is no Modifiers concept in Flutter so here are some alternatives in Flutter:</p><p><em>padding</em></p><pre>// compose<br>@Composable<br>fun Greeting() {<br>    Text(<br>        text = &quot;Hello&quot;,<br>        modifier = Modifier.padding(12.dp)<br>    )<br>}</pre><pre>// widgets<br><br>@override<br>  Widget build(BuildContext context) {<br>    return Padding(<br>      padding: EdgeInsets.all(12.0),<br>      child: Text(&#39;Hello&#39;),<br>    );<br>  }<br><br>// NOTE<br>// EdgeInsets.all(12) -&gt; padding(12.dp)<br>// EdgeInsets.only(top: 12) -&gt; padding(top = 12.dp)<br>// EdgeInsets.symmetric(vertical: 12) -&gt; padding(vertical = 12.dp)</pre><blockquote>Hint to speed up coding:</blockquote><p>You can wrap your widgets within any widget with this easy shortcut:</p><p><em>Alt + Enter</em> (Linux — Windows)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*pdAtaYXfMQ818udseEgGsg.png" /></figure><p><em>margin</em></p><pre>// compose<br>@Composable<br>fun Greeting() {<br>    Text(<br>        text = &quot;Hello&quot;,<br>        modifier = Modifier<br>            .background(color = Color.White) // background color<br>            .padding(12.dp) // this is margin<br>            .fillMaxWidth()<br>            .padding(12.dp) // this is padding<br>    )<br>}</pre><pre>// widgets<br>@override<br>  Widget build(BuildContext context) {<br>    return Container(<br>      color: Colors.white, // background color<br>      margin: EdgeInsets.all(12), // this is margin<br>      child: Text(&#39;Hello&#39;),<br>      padding: EdgeInsets.all(12), // this is padding<br>    ); <br>  }</pre><h4>Some Notes:</h4><ul><li>In Flutter, you can use the <strong>Container</strong> widget to add (color, margin, padding ..etc)</li></ul><p><em>clickable</em></p><pre>// compose<br>@Composable<br>fun Greeting() {<br>    Text(<br>        text = &quot;Hello&quot;,<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .clickable {<br>                // fire click<br>            }<br>    )<br>}</pre><pre>// widgets <br>/* some widgets like (ElevatedButton - OutlinedButton - TextButton - IconButton)<br>*  have onPressed which you can pass to them.<br>*  Unlike others you need to wrap your widget within [GestureDetector]<br>*<br>*  [GestureDetector] is a widget that takes [child widget and some actions]<br>*/<br><br> @override<br>  Widget build(BuildContext context) {<br>    return GestureDetector(<br>      child: Text(&#39;Hello&#39;),<br>      onTap: () {<br>        // fire click<br>      },<br>    );<br>  }</pre><p><em>combinedClickable (onClick — onLongClick —onDoubleClick)</em></p><pre>// compose<br>@OptIn(ExperimentalFoundationApi::class)<br>@Composable<br>fun Greeting() {<br>    Text(<br>        text = &quot;Hello&quot;,<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .combinedClickable(<br>                onClick = {<br><br>                },<br>                onLongClick = {<br><br>                },<br>                onDoubleClick = {<br><br>                }<br>            )<br>    )<br>}</pre><pre>// widgets<br>@override<br>  Widget build(BuildContext context) {<br>    return GestureDetector(<br>      child: Text(&#39;Hello&#39;),<br>      onTap: () {<br><br>      },<br>      onDoubleTap: () {<br>        <br>      },<br>      onLongPress: () {<br>        <br>      },<br>    );<br>  }</pre><h4>6 — LazyColumn</h4><pre>// compose<br>@Composable<br>fun Greeting() {<br>    val list = listOf(&quot;1&quot;, &quot;2&quot;, &quot;3&quot;)<br>    LazyColumn {<br>        items(list) {<br>            Text(text = it)<br>        }<br>    }<br>}</pre><pre>// widgets<br>  final List&lt;String&gt; list = [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;];<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return ListView.builder(<br>      scrollDirection: Axis.vertical, // Default is Axis.vertical<br>      itemCount: list.length,<br>      itemBuilder: (BuildContext context, int index) {<br>        return Text(list[index],);<br>      },<br>    );<br>  }</pre><h4>7 — LazyRow</h4><pre>// compose<br>@Composable<br>fun Greeting() {<br>    val list = listOf(&quot;1&quot;, &quot;2&quot;, &quot;3&quot;)<br>    LazyRow {<br>        items(list) {<br>            Text(text = it)<br>        }<br>    }<br>}</pre><pre>// widgets<br>  final List&lt;String&gt; list = [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;];<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return ListView.builder(<br>      scrollDirection: Axis.horizontal,<br>      itemCount: list.length,<br>      itemBuilder: (BuildContext context, int index) {<br>        return Text(list[index],);<br>      },<br>    );<br>  }</pre><h4>Some Notes:</h4><ul><li>In ListView change <strong>scrollDirection</strong> to <strong>Axis.horizontal</strong> to be as LazyRow in compose.</li></ul><h4>8 — Some Widgets you should know</h4><ul><li><strong>Center</strong>: A widget that centers its child within itself.</li><li><a href="https://youtu.be/CI7x0mAZiY0"><strong>Flexible</strong></a></li><li><a href="https://youtu.be/_rnZaagadyo"><strong>Expanded</strong></a></li><li><strong>SafeArea: </strong>A widget used to ensure that our app’s content remains visible and accessible on the screen, even when the device has notches, status bars, or any other intrusions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*VYGxi2l0hwpIMno04a_DaA.png" /><figcaption>Without <strong>SafeArea widget</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*bOYPHx081HjvX1RbBK0NiQ.png" /><figcaption>With <strong>SafeArea widget</strong></figcaption></figure><p>Resources 📘</p><ul><li><a href="https://docs.flutter.dev/ui/widgets">Widget catalog</a></li><li><a href="https://developer.android.com/jetpack/compose/designsystems/material3">Material Design 3 in Compose | Jetpack Compose | Android Developers</a></li><li><a href="https://genotechies.medium.com/flutter-button-types-and-what-are-the-deprecated-button-types-and-how-to-replace-them-c8506b8c398a">Flutter Button Types and What Are the Deprecated Button Types and How to Replace Them</a></li><li><a href="https://medium.com/huawei-developers/flutter-vs-jetpack-compose-comparison-learning-series-part-1-98f60a5f68c6">👨🏼‍💻Flutter vs Jetpack Compose (Comparison Learning Series Part -1)</a></li></ul><p>Next Article 📑</p><p><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-stateful-widget-vs-compose-states-part-3-0ab52f0a2ac9">Part 3 — Stateful Widget VS Compose states</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=875a07c09358" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter for Android Developers — Fully Guide to Learning Flutter — Part 1]]></title>
            <link>https://medium.com/@ahmed_shehata/flutter-for-android-developers-fully-guide-to-learning-flutter-da541c03c7e9?source=rss-15801ffeb1b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/da541c03c7e9</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Ahmed Shehata]]></dc:creator>
            <pubDate>Fri, 23 Feb 2024 13:11:11 GMT</pubDate>
            <atom:updated>2024-03-22T14:00:49.548Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter for Android Developers — Fully Guide to Learning Flutter — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QaOjMPdFspIsGLwT.png" /><figcaption>Flutter for everyone</figcaption></figure><p>Are you an Android developer keen to level up? Flutter offers a seamless transition with its cross-platform prowess and rapid development pace. This guide will show you how to smoothly <strong>shift from native Android to Flutter in just a few days</strong>. Let’s dive in, harnessing your expertise to unlock Flutter’s potential using a series of articles:</p><ul><li>Part 1 — Dart VS Kotlin ← (We’re here)</li><li><a href="https://medium.com/@ahmed_shehata/part-2-flutter-for-android-developers-widgets-vs-compose-875a07c09358">Part 2 — Widgets VS Compose</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-stateful-widget-vs-compose-states-part-3-0ab52f0a2ac9">Part 3 — Stateful Widget VS Compose states</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-libs-vs-android-libs-part-4-a68d3dbd3ed4">Part 4— Flutter libs VS Android libs</a></li><li><a href="https://medium.com/@ahmed_shehata/flutter-for-android-developers-flutter-community-part-5-bb27e552291b">Part 5— Flutter Community</a></li></ul><h4>Things you should know before starting:</h4><ul><li>Android</li><li>Kotlin</li><li>Compose (Basic knowledge)</li></ul><h3><strong>Introduction</strong></h3><p>As you know Flutter — is a powerful toolkit by Google for building cross-platform applications (Android — iOS — Web — Desktop)</p><p>We will learn Dart and Flutter, and how they differ from Android and kotlin.</p><h3>Setting Up Your Environment 🐾</h3><p>1 — <a href="https://dart.dev/get-dart">Install Dart</a></p><p>2 — <a href="https://docs.flutter.dev/get-started/install">Install Flutter SDK</a></p><p>3 — <a href="https://plugins.jetbrains.com/plugin/9212-flutter">Add Flutter plugin for Android Studio</a><em> (You can use VS code but I prefer Android Studio)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*pp18XRpo-Gl6YGDvdykqmQ.png" /><figcaption>Flutter plugin for AS</figcaption></figure><h4>Create your first Flutter project (Two ways)</h4><p>1 — Using Terminal (I prefer this way)</p><pre>flutter create first_app</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*pYaVdPzFx5OZRHngib0TmQ.png" /><figcaption>Terminal</figcaption></figure><p>2 — Using Android Studio</p><p>Go to: File → New → New Flutter project</p><blockquote>Sometimes I find the project files empty so I used the terminal way</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*7wmC9GOAa9p56HlOnOY4oA.png" /><figcaption>Android Studio</figcaption></figure><h4>Here we GOoO</h4><p>We will write all our code (till now) in the <strong>lib</strong> folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*9KfguWmzwxusYE3Cg7SWIQ.png" /><figcaption>Project Structure</figcaption></figure><blockquote>Write any single word you learn, don’t read it only</blockquote><h3>Kotlin VS Dart (Naming Convention)</h3><pre>// Kotlin<br>// Package Names -&gt; lowercase<br>// Class and Interface Names -&gt; PascalCase <br>// Function, Property Names and Variable Names -&gt; camelCase<br>// Constants -&gt; uppercase<br> <br>const val BASE_URL = &quot;base_url&quot;<br><br>class LoginRepository {<br><br>    private var isValid: Boolean = false<br><br>    fun login() {<br><br>    }<br>}</pre><pre>// Dart<br>// Package Names -&gt; lowercase<br>// Class and Interface Names -&gt; PascalCase <br>// Function, Property Names and Variable Names -&gt; camelCase<br>// Constants -&gt; camelCase<br>// File name -&gt; lowercase<br><br>const baseUrl = &quot;base_url&quot;;<br><br>class LoginRepository {<br><br>  var _isValid = false;<br><br>  void login() {<br><br>  }<br>}</pre><h3>Kotlin VS Dart (Syntax)</h3><blockquote>I will discuss here most of the things you may need (if you need more please check the <a href="https://dart.dev/language">Dart official documentation</a>)</blockquote><h4><strong>Variables</strong></h4><pre>// Kotlin<br>var name = &quot;Ahmed&quot;<br>var id = 5 <br>var sOld = true<br>var price = 10.0</pre><pre>// Dart<br>// var [variableName]<br>// {DataType} [variableName]<br><br>String name = &quot;Ahmed&quot;; // or -&gt; var name = &quot;Ahmed&quot;;<br>int id = 5; // or -&gt; var id =5;<br>bool isOld = true; // or -&gt; var isOld = true;<br>double price = 10.0; // ..etc</pre><h4>Constants</h4><pre>// Kotlin<br>// Runtime constant<br>val user = User()<br><br>// Compile-time constant<br>const val baseUrl = &quot;www.test.com&quot;</pre><pre>// Dart<br>// Runtime constant<br>final user = new User();<br><br>// Compile-time constant<br>const baseUrl = &quot;www.test.com&quot;;</pre><h4>Null safety &amp; Default value</h4><pre>// Kotlin<br>var name: String? = null <br><br>// if name == null, finalName will be &quot;default&quot;<br>var finalName = name ?: &quot;default&quot;</pre><pre>// Dart<br>String? name = null; <br><br>// if name == null, finalName will be &quot;default&quot;<br>String finalName = name ?? &quot;default&quot;;</pre><h4>Function</h4><pre>// Kotlin<br>fun add(x: Int, y: Int): Int {<br>    return x + y <br>}<br><br>fun compressFile(path: String) {<br>  //...<br>}</pre><pre>// Dart<br>int add(int x, int y) {<br>    return x + y;<br>}<br><br>void compressFile(String path) {<br>  //...<br>}</pre><h4>Lambda Expression</h4><pre>// Kotlin<br>// Lambda expression with inferred type<br>val square = { x: Int -&gt; x * x }<br><br>// Lambda expression as an argument<br>fun processNumbers(numbers: List&lt;Int&gt;, action: (Int) -&gt; Unit) {<br>    for (number in numbers) {<br>        action(number)<br>    }<br>}</pre><pre>// Dart<br>// Arrow function with inferred type<br>int Function(int) square = (x) =&gt; x * x;<br><br>// Lambda expression as an argument<br>void processNumbers(List&lt;int&gt; numbers, void Function(int) action) {<br>  for (int number in numbers) {<br>    action(number);<br>  }<br>}</pre><h4>Class &amp; inheritance &amp; implementation</h4><pre>// kotlin<br>class A : B, C <br></pre><pre>// Dart<br>class A extends B implements C<br></pre><h4>Enum</h4><pre>// kotlin<br>enum Color { RED,BLUE,BLACK }<br></pre><pre>// Dart<br>enum Color { red,blue,black }<br></pre><h4>Data class</h4><pre>// kotlin<br>data class User (<br>val id: Int,<br>val name: String<br>)<br></pre><pre>// Dart<br>class User {<br><br>final int id;<br>final String name;<br><br>User(this.id, this.name);<br>}<br></pre><h4>Sealed class</h4><pre>// Kotlin<br>sealed class UIState {<br>    object Loading : UIState()<br>    data class Error(val message: String) : UIState()<br>    data class Success(val data: List&lt;String&gt;) : UIState()<br>}<br><br>// how to use <br>fun main(){<br>  val state: UIState = UIState.Loading<br>  when(state) {<br>      UIState.Loading -&gt; {<br><br>      }<br>      is UIState.Error -&gt; {<br>          <br>      }<br>      is UIState.Success -&gt; {<br>          <br>      }<br>  }<br>}</pre><pre>// Dart<br>sealed class UIState {}<br><br>class Loading extends UIState {}<br><br>class Error extends UIState {}<br><br>class Success extends UIState {<br>  final List&lt;String&gt; _data;<br><br>  Success(this._data);<br>}<br><br>// how to use <br>void main(){<br>  final UIState state = Loading();<br>  var message = switch (state) {<br>      Loading() =&gt; {<br>        <br>      },<br>      Error() =&gt; {<br><br>      },<br>      Success() =&gt; {<br><br>      }<br>    };<br>}</pre><h4>Exception Handling</h4><pre>// Dart <br>try {<br> // Code that may throw an exception<br>} on FormatException catch (e) {<br> // Handle FormatException<br>} on Exception catch (e) {<br> // Handle other exceptions<br>} catch (e) {<br> // Catch any remaining exceptions<br>} finally {<br> // Cleanup code<br>}<br></pre><pre>// Kotlin<br><br>try {<br> // Code that may throw an exception<br>} catch (e) {<br> // Handle the exception<br>} finally {<br> // Code that always executes, whether an exception is thrown or not<br>}<br></pre><h4>Conditions Handling &amp; Looping</h4><p>(If — while — do while) are the same in dart</p><pre>// Kotlin<br>val x = 5<br>when (x) {<br>   1 -&gt; println(&quot;x is 1&quot;)<br>   2 -&gt; println(&quot;x is 2&quot;)<br>   3, 4 -&gt; println(&quot;x is 3 or 4&quot;)<br>   in 5..10 -&gt; println(&quot;x is between 5 and 10&quot;)<br>   else -&gt; println(&quot;x is neither 1 nor 2 nor 3 nor 4&quot;)<br>}</pre><pre>// Dart<br>var x = 5;<br>switch (x) {<br>   case 1:<br>     print(&quot;x is 1&quot;);<br>     break;<br>   case 2:<br>     print(&quot;x is 2&quot;);<br>     break;<br>   case 3:<br>   case 4:<br>     print(&quot;x is 3 or 4&quot;);<br>     break;<br>   default:<br>     print(&quot;x is neither 1 nor 2 nor 3 nor 4&quot;);<br>}</pre><h4>Extensions</h4><pre>// kotlin<br>fun String.toFullName(): String {<br>    return this + &quot;last&quot;<br>}</pre><pre>// Dart<br>extension StringExtension on String {<br><br>String toFullName() {<br>    return this + &quot;last&quot;;<br>}<br><br>// add more extensions on string here<br>}</pre><h4>Access modifiers</h4><pre>// Kotlin<br>// Public: members are public by default.<br>// Private<br>// Protected<br>// internal<br><br>class LoginViewModel(<br>    private val getMoviesListUseCase: GetMoviesListUseCase,<br>) : ViewModel() {<br><br>    private var isOnline = false<br><br><br>    fun getMovies(): List&lt;MovieDomainModel&gt; {<br>        return getMoviesListUseCase.execute()<br>    }<br><br>    override fun onCleared() {<br>        // clean up resources<br>        super.onCleared()<br>    }<br><br>}</pre><pre>// Dart<br>// Public: members are public by default.<br>// Private: by prefixing an underscore (_) to their names.<br>// Protected<br><br>class LoginViewModel extends ViewModel {<br>  final GetMoviesListUseCase _getMoviesListUseCase;<br>  bool _isOnline = false;<br><br>  // Constructor<br>  LoginViewModel(this._getMoviesListUseCase);<br><br>  List&lt;MovieDomainModel&gt; getMovies() {<br>    return _getMoviesListUseCase.execute();<br>  }<br><br>  @override<br>  void onCleared() {<br>    // clean up resources<br>    super.onCleared();<br>  }<br>}<br></pre><h4>Named &amp; Default Parameters</h4><ul><li>Named Parameters</li></ul><pre>// Kotlin<br>fun greet(name: String, greeting: String) {<br>    println(&quot;$greeting, $name!&quot;)<br>}<br><br>fun main() {<br>    greet(name = &quot;Ahmed&quot;, greeting = &quot;Hello&quot;) // Output: Hello, Ahmed!<br>}</pre><pre>// Dart<br>void greet({required String name, required String greeting}) {<br>    print(&#39;$greeting, $name!&#39;);<br>}<br><br>void main() {<br>    greet(name: &quot;Ahmed&quot;, greeting: &quot;Hello&quot;); // Output: Hello, Ahmed!<br>}</pre><ul><li>Default Parameters</li></ul><pre>// Kotlin<br>fun greet(name: String = &quot;Ahmed&quot;, greeting: String = &quot;Hello&quot;) {<br>    println(&quot;$greeting, $name!&quot;)<br>}<br><br>fun main() {<br>    greet() // Output: Hello, Ahmed!<br>}</pre><pre>// Dart<br>void greet({String name = &quot;Ahmed&quot;, String greeting = &#39;Hello&#39;}) {<br>    print(&#39;$greeting, $name!&#39;);<br>}<br><br>void main() {<br>    greet(); // Output: Hello, Ahmed!<br>}</pre><p>Important notes 📕</p><ul><li>Dart has a <strong>single-threaded</strong> execution model.</li><li>You need to add a semicolon to the end of a statement.</li><li><strong>void</strong> and <strong>new</strong> keywords are optional in Dart.</li><li>There is <strong>no interface</strong> in Dart, just use <strong>abstract class.</strong></li><li>Dart does not support <strong>multiple inheritance</strong> like (java — kotlin).</li><li>Dart has <strong>no private </strong>keyword instead use an <strong>underscore</strong> before the class name method or field (_).</li></ul><p>Resources 📘</p><p><a href="https://dart.dev/language">Introduction to Dart</a></p><p>Next Article 📑</p><p><a href="https://medium.com/@ahmed_shehata/part-2-flutter-for-android-developers-widgets-vs-compose-875a07c09358">Part 2— Widgets VS Compose</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da541c03c7e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose Pie Chart Circle - Deep understanding]]></title>
            <link>https://medium.com/@ahmed_shehata/compose-pie-chart-circle-deep-understanding-d09f1352043c?source=rss-15801ffeb1b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d09f1352043c</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[pie-charts]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Ahmed Shehata]]></dc:creator>
            <pubDate>Tue, 14 Nov 2023 13:33:57 GMT</pubDate>
            <atom:updated>2023-11-14T13:57:32.546Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Compose </strong>Pie <strong>Chart Circle - Deep Understanding</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*rJlFpjTJd7K2jBRz8ydzTA.png" /></figure><p>First of all, we need to know how to draw an <strong>Arc</strong> in Compose using <strong>Canvas</strong></p><blockquote>The Canvas in Jetpack Compose is a Composable function that wraps the native canvas APIs from the UI toolkit.<br>drawLine — drawPath — drawCircle — drawText ..etc</blockquote><h3><strong>To draw an Arc you should determine the following stuff:</strong></h3><p>1- color<br>2- startAngle<br>3- sweepAngle</p><pre>Canvas(<br>      modifier = Modifier.size(200.dp).background(Color.Gray),<br>      onDraw = {<br>            drawArc(<br>                    color = Color.Red,<br>                    startAngle = 0f,<br>                    sweepAngle = 90f,<br>                    useCenter = true,<br>                  )<br>            })</pre><p>Here I used Canvas with a fixed size (200 dp) and a Gray background color to draw an Arc but the output is like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/1*DA0Bo2okD3HBXVJRXC_01g.png" /><figcaption>Quarter Circle NOT Arc</figcaption></figure><p>To Fix this and make it an Arc just change the <strong>useCenter and style </strong>will make many changes together:</p><pre>drawArc(<br>   color = Color.Red,<br>   startAngle = 0f,<br>   sweepAngle = 90f,<br>   useCenter = true,<br>   style = Stroke(<br>       width = 4f,<br>       cap = StrokeCap.Round,<br>       join = StrokeJoin.Round<br>         )<br>     )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/1*bwWb0M2qM5TvJ4QMW9tPkA.png" /></figure><pre>drawArc(<br>   color = Color.Red,<br>   startAngle = 0f,<br>   sweepAngle = 90f,<br>   useCenter = false,<br>   style = Stroke(<br>       width = 4f,<br>       cap = StrokeCap.Round,<br>       join = StrokeJoin.Round<br>         )<br>     )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/1*Lcunl_3rMHwdreYE3XOi3A.png" /><figcaption>That’s it</figcaption></figure><h3>Let’s talk about <strong>startAngle</strong> and sweepAngle</h3><p><strong>startAngle</strong>: Starting angle in degrees (0 represents 3 o’clock) <br><strong>sweepAngle</strong>: Size of the arc in degrees that is drawn <strong>clockwise</strong> relative to startAngle</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*n_eybg8B68JW8BhPh2ofnw.png" /></figure><blockquote>For example: If you wanted to draw an Arc starting from 120° to 210°<br>so your</blockquote><blockquote><strong>startAngle = 120f &amp; sweepAngle = 210–120 = 90f</strong></blockquote><pre>drawArc(<br>   color = Color.Red,<br>   startAngle = 120f,<br>   sweepAngle = 90f,<br>   useCenter = false,<br>   style = Stroke(<br>       width = 4f,<br>       cap = StrokeCap.Round,<br>       join = StrokeJoin.Round<br>         )<br>     )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/142/1*e6i0E3j0dyzht1b6wSHsmw.png" /></figure><h3>Let’s draw our shape</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*rJlFpjTJd7K2jBRz8ydzTA.png" /></figure><p>Here we have some Arcs (each Arc has a <strong>color</strong> and a <strong>value</strong>) so let’s represent this as a wrapper class:</p><pre>data class ChartModel(<br>  val value: Float,<br>  val color: Color,<br>)</pre><p>Create a list that contains all data:</p><pre>val charts = listOf(<br>    ChartModel(value = 20f, color = Color.Black),<br>    ChartModel(value = 30f, color = Color.Gray),<br>    ChartModel(value = 40f, color = Color.Green),<br>    ChartModel(value = 10f, color = Color.Red),<br>)</pre><p>Create our Composable to draw the custom shape</p><pre>@Composable<br>private fun ChartCirclePie(<br>        modifier: Modifier,<br>        charts: List&lt;ChartModel&gt;,<br>        size: Dp = 200.dp,<br>        strokeWidth: Dp = 16.dp<br>    ) {<br>        Canvas(modifier = modifier<br>            .size(size)<br>            .background(Color.LightGray)<br>            .padding(12.dp), <br><br>             onDraw = {<br><br>            var startAngle = 0f<br>            var sweepAngle = 0f<br><br>            charts.forEach {<br><br>                // TODO calculate sweepAngle<br>                <br>                drawArc(<br>                    color = it.color,<br>                    startAngle = startAngle,<br>                    sweepAngle = sweepAngle,<br>                    useCenter = false,<br>                    style = Stroke(<br>                        width = strokeWidth.toPx(),<br>                        cap = StrokeCap.Round,<br>                        join = StrokeJoin.Round<br>                    )<br>                )<br><br>                // TODO change startAngle<br>            }<br>            <br>        })<br><br>    }</pre><p>Here I have looped over the whole list to draw each Arch with its value and color but the <strong>sweepAngle</strong> and <strong>startAngle</strong> are different for arc to another so how to <strong>calculate</strong> them:</p><p>1- <strong>sweepAngle:</strong></p><blockquote><strong><em>sweepAngle = (value / 100) * 360</em></strong></blockquote><blockquote>1- Calculate the fraction of the value out of 100</blockquote><blockquote>2- Multiply the fraction by 360 to get the sweep angle</blockquote><p>2- <strong>startAngle</strong>:</p><blockquote><strong><em>startAngle += sweepAngle</em><br></strong>For every arc will be drawn the startAngle will be the same as startAngle plus the new sweepAngle</blockquote><h3>The Final code will be 🔥</h3><pre>@Composable<br>private fun ChartCirclePie(<br>        modifier: Modifier,<br>        charts: List&lt;ChartModel&gt;,<br>        size: Dp = 200.dp,<br>        strokeWidth: Dp = 16.dp<br>    ) {<br>        Canvas(modifier = modifier<br>            .size(size)<br>            .background(Color.LightGray)<br>            .padding(12.dp), <br><br>             onDraw = {<br><br>            var startAngle = 0f<br>            var sweepAngle = 0f<br><br>            charts.forEach {<br><br>                sweepAngle = (it.value / 100) * 360<br>                <br>                drawArc(<br>                    color = it.color,<br>                    startAngle = startAngle,<br>                    sweepAngle = sweepAngle,<br>                    useCenter = false,<br>                    style = Stroke(<br>                        width = strokeWidth.toPx(),<br>                        cap = StrokeCap.Round,<br>                        join = StrokeJoin.Round<br>                    )<br>                )<br><br>                startAngle += sweepAngle<br>            }<br>            <br>        })<br><br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/183/1*sac6VTdDUl4yJn2QmM0QNQ.png" /><figcaption>Final LOOK</figcaption></figure><h3>💐Bouns</h3><p><strong>Draw a text inside the shape in the center of it</strong></p><p>To draw a text we need to measure the<strong> top left</strong> <strong>point</strong> of the text</p><pre>val myText = &quot;ChartCirclePie&quot;<br>val textMeasurer = rememberTextMeasurer()<br>val textLayoutResult = textMeasurer.measure(text = AnnotatedString(myText))<br>val textSize = textLayoutResult.size</pre><pre>drawText(<br>   textMeasurer, myText,<br>   topLeft = Offset(<br>        (this.size.width - textSize.width) / 2f,<br>         (this.size.height - textSize.height) / 2f<br>     ),<br>)</pre><h3>Final code 🙌</h3><pre>@Composable<br>    private fun ChartCirclePie(<br>        modifier: Modifier,<br>        charts: List&lt;ChartModel&gt;,<br>        size: Dp = 200.dp,<br>        strokeWidth: Dp = 16.dp<br>    ) {<br>        val myText = &quot;ChartCirclePie&quot;<br>        val textMeasurer = rememberTextMeasurer()<br>        val textLayoutResult = textMeasurer.measure(text = AnnotatedString(myText))<br>        val textSize = textLayoutResult.size<br><br>        Canvas(modifier = modifier<br>            .size(size)<br>            .background(Color.LightGray)<br>            .padding(12.dp), onDraw = {<br><br>            var startAngle = 0f<br>            var sweepAngle = 0f<br><br>            charts.forEach {<br>                val brush = createStripeBrush(<br>                    stripeColor = it.color,<br>                    stripeWidth = 2.dp,<br>                    stripeToGapRatio = 2f<br>                )<br><br>                sweepAngle = (it.value / 100) * 360<br>                <br>                drawArc(<br>                    color = it.color,<br>                    startAngle = startAngle,<br>                    sweepAngle = sweepAngle,<br>                    useCenter = false,<br>                    style = Stroke(<br>                        width = strokeWidth.toPx(),<br>                        cap = StrokeCap.Round,<br>                        join = StrokeJoin.Round<br>                    )<br>                )<br><br>                startAngle += sweepAngle<br>            }<br><br>            drawText(<br>                textMeasurer, myText,<br>                topLeft = Offset(<br>                    (this.size.width - textSize.width) / 2f,<br>                    (this.size.height - textSize.height) / 2f<br>                ),<br>            )<br>        })<br><br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*rJlFpjTJd7K2jBRz8ydzTA.png" /><figcaption>Final LOOK</figcaption></figure><h3><strong>Follow me for more 🙏</strong></h3><p>Join my <a href="https://t.me/androidy_me">telegram</a> channel about new android topics</p><p><a href="https://www.linkedin.com/in/ahmed-she7ata/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d09f1352043c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>