<?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 Dharmesh Mansata on Medium]]></title>
        <description><![CDATA[Stories by Dharmesh Mansata on Medium]]></description>
        <link>https://medium.com/@dharmeshm10?source=rss-29d6e3861d67------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ypbDP30RK7juPoezjP0OcQ.jpeg</url>
            <title>Stories by Dharmesh Mansata on Medium</title>
            <link>https://medium.com/@dharmeshm10?source=rss-29d6e3861d67------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 06 Jun 2026 09:41:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dharmeshm10/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[Architecture Document for a Modern App]]></title>
            <link>https://dharmeshm10.medium.com/architecture-document-for-a-modern-app-f626d339af0d?source=rss-29d6e3861d67------2</link>
            <guid isPermaLink="false">https://medium.com/p/f626d339af0d</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[scalable-mobile-app]]></category>
            <category><![CDATA[bloc]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Dharmesh Mansata]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 04:46:06 GMT</pubDate>
            <atom:updated>2024-09-19T04:46:06.820Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Designing a robust architecture for modern apps is critical to ensuring scalability, maintainability, and flexibility for future enhancements. In my latest project, I used Flutter alongside the BLoC pattern to build a structured, modular app with seamless state management. By focusing on best practices, such as a layered approach and clean separation of concerns, we were able to integrate features like Firebase Auth and RESTful APIs with ease. This architecture allows the app to adapt swiftly to future changes while ensuring optimal performance.</em></p><p><strong>1. Cross-Platform Responsiveness</strong></p><p>Flutter’s versatility across mobile, web, and desktop platforms makes it a fantastic choice for modern app development. For responsive design, we can leverage techniques like <strong>MediaQuery</strong> and <strong>AspectRatio</strong>, or create our own <strong>Screen Utility</strong> (like the one I built: <a href="https://github.com/dharmeshm10/seed/blob/main/lib/common/configs/screen_utils.dart">Reference code</a>). While there are great packages out there, like <a href="https://pub.dev/packages/flutter_screenutil"><strong>flutter_screenutil</strong></a>, I’m a firm believer in the DIY approach — why outsource when you can keep it in-house? Of course, platform-specific configurations and theme-based implementations can also be easily integrated for a seamless, consistent user experience. <a href="https://github.com/dharmeshm10/seed/tree/main/lib/presentation/themes">Reference code</a>. After all, building custom solutions is half the fun in coding!</p><p><strong>2. Secure Frontend-Backend Communication</strong></p><p>Use https for all network call with help of alice [ <a href="https://github.com/jhomlala/alice">https://github.com/jhomlala/alice</a> ] you can verify each screen APIs. For more securing use JWT or refresh token method. For offline sensitive information store use flutter_secure_storage [Ref: <a href="https://pub.dev/packages/flutter_secure_storage">https://pub.dev/packages/flutter_secure_storage</a> ]. Please find below diagram for more:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0I2TxbAs1AHLR_-QENyLNA.png" /><figcaption><strong>Frontend-Backend Communication</strong></figcaption></figure><p><strong>3. Flexibility for Future Enhancements</strong></p><p>The <strong>BLoC pattern</strong> is a powerhouse for handling complex logic, which is why we’ve implemented it extensively. In one of my projects, we used a layered architecture — <strong>Presentation</strong>, <strong>Domain</strong>, and <strong>Data</strong> — inspired by <a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-cleanarchitecture.html">Uncle Bob’s Clean Architecture</a>. For example, in the <strong>Reward Module</strong>, <strong>RewardBloc</strong> manages all the reward-related logic, processing events like <strong>EarnPoints</strong> and <strong>RedeemReward</strong> to ensure smooth user interactions. The beauty of this approach? Adding new modules, like a <strong>Transaction</strong> or <strong>Chat</strong> module, follows the same principle, making future enhancements almost effortless. The key is flexibility — entities act as the bridge between the domain and repository, ensuring they speak the same language. Think of it like building a LEGO set: once you have the foundation, adding new pieces is a breeze!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*4C6xzut4kod2dURXq01V-w.png" /><figcaption>Uncle Bob’s Recommendations on Clean Code Architecture</figcaption></figure><p><strong>4.Scalable Database Design</strong></p><p>Our app is built to handle up to <strong>100,000 users</strong>, so naturally, we opted for <strong>GraphQL</strong> — the cool middleman between the frontend and databases. Why GraphQL, you ask? Simple: it’s like ordering a combo meal instead of separate dishes. With just <strong>one API call</strong>, it fetches all the data you need, even if you’ve got a bunch of entity tables, minimizing those tedious round trips to the server.</p><p>Pairing <strong>GraphQL</strong> with the <strong>BLoC pattern</strong> is like getting the best of both worlds. We define <strong>resolvers</strong> in GraphQL to handle the database, while <strong>BLoC</strong> centralizes all the app’s business logic. And because we’re talking about 100,000 users, security’s tight — <strong>JWT</strong> secures our queries and mutations, with rate limiting for good measure. As for deployment? We’ve got <strong>versioning</strong>, <strong>feature toggles</strong>, and <strong>phased rollouts</strong> to keep everything smooth. It’s like launching a spaceship but with fewer explosions!</p><p><strong>5.Separation of Business and View Logic</strong></p><p>Every good app deserves a clear separation between <strong>business logic</strong> and <strong>view logic</strong> — after all, you wouldn’t want the brains of the operation tangled up in the presentation, right? That’s where <strong>BLoC</strong> and <strong>Provider</strong> come in. We chose this combo because it handles complex logic like a pro and keeps things scalable. With <strong>BLoC</strong>, the business logic stays neatly tucked away, completely independent of the UI. This way, when the app scales (and it will), we can make changes to the logic without touching the interface. It’s like having a personal chef: they handle the cooking, while you just enjoy the meal!</p><p><strong>6.Deployment Strategy</strong></p><p><strong>Feature flags</strong> are like secret switches hidden in your app’s code — flick them on or off, and voilà! Features appear or disappear. In my case, I rolled out a reward system for just <strong>5% of users</strong> using a simple JSON config file or <strong>Firebase Remote Config</strong>. It’s kind of like giving VIP access to a select few while the rest of the crowd waits at the gates.</p><p>Here’s the beauty of it: let’s say we’ve got a limited number of coupon codes. We launch to 5% of users, filtering by user ID or some unique identifier. Once those codes are gobbled up, we simply flip the feature flag switch, and boom! The reward system is down for maintenance (or as I like to call it, ‘coupon rehab’). If we need real-time updates, <strong>ably_flutter</strong> comes to the rescue with live events [Ref: <a href="https://pub.dev/packages/ably_flutter">https://pub.dev/packages/ably_flutter</a>].</p><p>And when we push out a new version of <strong>GraphQL</strong> but the older app starts acting like a grumpy grandpa? No problem! <strong>Ably_flutter</strong> can clear local storage in real time, helping things run smoothly again. Plus, both <strong>Play Store</strong> and <strong>App Store</strong> have us covered with phased rollouts and <strong>Alpha/Beta testing</strong>. So, it’s all under control… most of the time!</p><p>And there you have it — building apps with scalable architecture, toggling features like a pro, and keeping everything under control (or at least pretending to!). Whether it’s handling reward rollouts for 5% of users or taming a grumpy old version of GraphQL, we’ve got the tools and techniques to make it happen.</p><p>If you’re itching to dive deeper and see all this in action, check out the <strong>seed repository</strong> I’ve put together: <a href="https://github.com/dharmeshm10/seed">GitHub: dharmeshm10/seed</a>. Just don’t forget to flip the right switches!</p><p>Thanks for sticking around till the end! If you have any questions, ideas, or just want to chat about all things Flutter and app architecture, feel free to connect with me on <a href="https://www.linkedin.com/in/dharmeshm10/"><strong>LinkedIn</strong></a> or catch me on <a href="https://stackoverflow.com/users/4641505/dharmesh-mansata"><strong>Stack Overflow</strong></a>. I’d love to hear from you!</p><p>Until then, happy coding and remember — always flip the right switches!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f626d339af0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Short summary of Unit test, Widget test, Integration test in flutter.]]></title>
            <link>https://dharmeshm10.medium.com/short-summary-of-unit-test-widget-test-integration-test-in-flutter-e450a6f707a4?source=rss-29d6e3861d67------2</link>
            <guid isPermaLink="false">https://medium.com/p/e450a6f707a4</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Dharmesh Mansata]]></dc:creator>
            <pubDate>Wed, 02 Dec 2020 05:00:03 GMT</pubDate>
            <atom:updated>2020-12-02T06:07:10.969Z</atom:updated>
            <content:encoded><![CDATA[<h3>Short summary of Unit test, Widget test, Integration test in Flutter.</h3><p>What is <strong>Unit Test </strong>?</p><ul><li>To test correctness of a logical unit.</li><li>External dependencies mocked using <strong>Mockito</strong></li></ul><p><strong>dependencies</strong>:<br> test<strong>: &lt;version&gt;<br> </strong>mockito<strong>: &lt;version&gt;</strong></p><p>For better understanding we are taking example of Unit Test. Unit Test generally belong to <strong>flutter_test</strong> package.</p><pre>import &#39;package:flutter_test/flutter_test.dart&#39;;</pre><p>Suppose , there are class name counter and its having increment / decrement variable.</p><pre>class Counter {<br>   int value = 0;<br>   void increment() =&gt; value++;<br>   void decrement() =&gt; value - ;<br>}</pre><p>Now,</p><pre>import &#39;package:flutter_test/flutter_test.dart&#39;;<br><br>void main() {<br><br>    group(&#39;Counter&#39;, () {<br>          test(&#39;value should start at 0&#39;, () {<br>          expect(Counter().value, 0);<br>     });<br><br>    test(&#39;value should be incremented&#39;, () {<br>         final counter = Counter();<br>         counter.increment();<br>         expect(counter.value, 1);<br>    });<br><br>    test(&#39;value should be decremented&#39;, () {<br>         final counter = Counter();<br>         counter.decrement();<br>         expect(counter.value, -1);<br>    });<br>  });<br>}</pre><p>Above are simple summary of Unit Test, we can write with mock data as well, Let’s check example with mock data.</p><pre>class Post {<br>  dynamic data;<br>  Post.fromJson(this.data);<br>}</pre><pre>Future&lt;Post&gt; fetchPost(http.Client client) async {<br>  final response = await client.get(&#39;&lt;url&gt;&#39;);<br><br>  if (response.statusCode == 200) {<br>    return Post.fromJson(<br>        json.decode(response.body)<br>    );<br>  } else {<br>    throw Exception(&#39;Failed to load post&#39;);<br>  }<br>}</pre><p>We should divide to abstract class file for better structure. Now,</p><pre>class MockClient extends Mock implements http.Client {}</pre><p>Now test case,</p><pre>group(&#39;fetchPost&#39;, () {<br><br>  test(&#39;returns a Post if the http call completes&#39;, () async {<br>    final client = MockClient();<br>    when(client.get(&#39;&lt;url&gt;&#39;)).thenAnswer((_) async =&gt;<br>    http.Response(&#39;{&quot;title&quot;: &quot;Test&quot;}&#39;, 200));<br><br>    expect(await fetchPost(client), const TypeMatcher&lt;Post&gt;());<br>  });<br><br>  test(&#39;throws an exception if the http call throws an error&#39;, () {<br>    final client = MockClient();<br>    when(client.get(&#39;&lt;url&gt;&#39;))<br>        .thenAnswer((_) async =&gt; http.Response(&#39;Not Found&#39;, 404));<br>    expect(fetchPost(client), throwsException);<br>  });<br>}</pre><p>What is <strong>Widget</strong> <strong>Test </strong>?</p><p>Test a single widget</p><ul><li>To verify UI look.</li><li>To check how it responds to actions</li></ul><p>To add dependencies</p><p><strong>flutter_test:<br> sdk: flutter</strong></p><p>Let’s take an examples of widget</p><pre>class WidgetTest extends StatelessWidget {<br>  final String title;<br>  final String message;<br>  const WidgetTest({Key key, @required this.title, @required this.message})<br>      : super(key: key);<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Flutter Demo&#39;,<br>      home: Scaffold(<br>        appBar: AppBar(title: Text(title)),<br>        body: Center(child: Text(message)),<br>      ),<br>    );<br>  }<br>}</pre><p>If you want to find widget then below terms are important.</p><p>Find</p><ol><li>find.text</li><li>find.byWidget</li><li>find.byKey</li><li>find.byType</li></ol><p>Action</p><p><strong>enterText()</strong></p><blockquote>tester.enterText(find.byType(TextField), ‘hi’);</blockquote><p><strong>Tap()</strong></p><blockquote>tester.tap(find.byType(FloatingActionButton));</blockquote><p><strong>drag()</strong></p><blockquote>tester.drag(find.byType(Dismissible), Offset(500.0, 0.0));</blockquote><p><strong>How to rebuild?</strong></p><blockquote>pump(); &amp; pumpAndSettle();</blockquote><p>Now writing above widget test :</p><pre>testWidgets(&#39;MyWidget has a title and message&#39;,<br>(WidgetTester tester) async {<br><br>await tester.pumpWidget(MyWidget(title: &#39;D&#39;, message: &#39;M&#39;));<br><br><br>final titleFinder = find.text(&#39;D&#39;);<br>final messageFinder = find.text(&#39;M&#39;);<br><br><br>expect(titleFinder, findsOneWidget);<br>expect(messageFinder, findsOneWidget);<br><br><br><br>});</pre><p>If there are action included then using pump() / pumpAndSettle() we can write</p><pre>testWidgets(&#39;Add and remove a todo&#39;, <br>(WidgetTester tester) async {<br>  await tester.pumpWidget(TodoList());<br>  await tester.enterText(find.byType(TextField), &#39;hi&#39;);<br>  await tester.tap(find.byType(FloatingActionButton));<br><br>  await tester.pump();<br><br>  expect(find.text(&#39;flutter&#39;), findsOneWidget);<br>  await tester.drag(find.byKey(Dismissible), Offset(500.0, 0.0));<br><br>  await tester.pumpAndSettle();<br><br>  expect(find.text(&#39;flutter&#39;), findsNothing);<br>});</pre><p>What is <strong>Integrated Test</strong> ?</p><ul><li>For a larger part of application — important scenarios</li><li>To test all widgets and services work together</li></ul><p>For example,</p><p>A — Displaying Name</p><p>B — Edit Name</p><p>Suppose, you are editing your name on page B and you pop / get back to Page A then you must have <strong>UPDATED NAME </strong>Otherwise scenario is false.</p><p>So, There are more scenario we can cover but as per lager application.</p><p><strong>— — — — Very Simple Example</strong> <strong>for covering all scenarios — — — —</strong></p><p>Switch A is for Starting the Tube-light<br>So when Switch A is Enable You need to Test,</p><blockquote>Positive: There is Light in Room.<br>Negative : There is No Dark in Room.</blockquote><blockquote>Only positive is not good need to cover negative too.</blockquote><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e450a6f707a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set a dynamic screen as per reference height & width and font size in flutter?]]></title>
            <link>https://dharmeshm10.medium.com/how-to-set-a-dynamic-screen-as-per-reference-height-width-and-font-size-in-flutter-e30218e7556?source=rss-29d6e3861d67------2</link>
            <guid isPermaLink="false">https://medium.com/p/e30218e7556</guid>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Dharmesh Mansata]]></dc:creator>
            <pubDate>Wed, 05 Jun 2019 11:52:39 GMT</pubDate>
            <atom:updated>2019-06-05T11:52:39.734Z</atom:updated>
            <content:encoded><![CDATA[<p>I am familiar with iOS app development but newbie in a flutter, For those who are coming from iOS platform, we have a concept of a proportional ratio and constraint similar we need in the proportional ratio in a flutter as well.</p><p>With the use of <a href="https://api.flutter.dev/flutter/widgets/MediaQuery-class.html">MediaQuery</a>, We can set screen size and height as per the given reference size.</p><p><strong>Let’s code :</strong></p><pre><strong>import &#39;package:flutter/material.dart&#39;</strong>;</pre><pre><strong>class </strong>UIUtills {<br>  <strong>factory </strong>UIUtills() {<br>    <strong>return </strong><em>_singleton</em>;<br>  }</pre><pre>  <strong>static final </strong>UIUtills <em>_singleton </em>= UIUtills._internal();</pre><pre>  UIUtills._internal() {<br>    print(<strong>&quot;Instance created UIUtills&quot;</strong>);<br>  }</pre><pre><em>//region Screen Size and Proportional according to device<br>  </em>double <strong>_screenHeight</strong>;<br>  double <strong>_screenWidth</strong>;</pre><pre>  double <strong>get screenHeight </strong>=&gt; <strong>_screenHeight</strong>;</pre><pre>  double <strong>get screenWidth </strong>=&gt; <strong>_screenWidth</strong>;</pre><pre>  <strong>final </strong>double <strong>_refrenceScreenHeight </strong>= 640;<br>  <strong>final </strong>double <strong>_refrenceScreenWidth </strong>= 360;</pre><pre>  <strong>void </strong>updateScreenDimesion({double width, double height}) {<br>    <strong>_screenWidth </strong>= (width != <strong>null</strong>) ? width : <strong>_screenWidth</strong>;<br>    <strong>_screenHeight </strong>= (height != <strong>null</strong>) ? height : <strong>_screenHeight</strong>;<br>  }</pre><pre>  double getProportionalHeight({double height}) {<br>    <strong>if </strong>(<strong>_screenHeight </strong>== <strong>null</strong>) <strong>return </strong>height;<br>    <strong>return _screenHeight </strong>* height / <strong>_refrenceScreenHeight</strong>;<br>  }</pre><pre>  double getProportionalWidth({double width}) {<br>    <strong>if </strong>(<strong>_screenWidth </strong>== <strong>null</strong>) <strong>return </strong>width;<br>    <strong>var </strong>w = <strong>_screenWidth </strong>* width / <strong>_refrenceScreenWidth</strong>;</pre><pre>    <strong>return </strong>w.ceilToDouble();<br>  }</pre><pre><em>//endregion<br>//region TextStyle<br>  </em>TextStyle getTextStyleRegular(<br>      {String fontName = <strong>&#39;Roboto-Regular&#39;</strong>,<br>      int fontsize = 12,<br>      Color color,<br>      bool isChangeAccordingToDeviceSize = <strong>true</strong>,<br>      double characterSpacing,<br>      double lineSpacing}) {<br>    double finalFontsize = fontsize.toDouble();</pre><pre>    <strong>if </strong>(isChangeAccordingToDeviceSize &amp;&amp; <strong>this</strong>.<strong>_screenWidth </strong>!= <strong>null</strong>) {<br>      finalFontsize = (finalFontsize * <strong>_screenWidth</strong>) / <strong>_refrenceScreenWidth</strong>;<br>    }</pre><pre>    <strong>if </strong>(characterSpacing != <strong>null</strong>) {<br>      <strong>return </strong>TextStyle(<br>          fontSize: finalFontsize,<br>          fontFamily: fontName,<br>          color: color,<br>          letterSpacing: characterSpacing);<br>    } <strong>else if </strong>(lineSpacing != <strong>null</strong>) {<br>      <strong>return </strong>TextStyle(<br>          fontSize: finalFontsize,<br>          fontFamily: fontName,<br>          color: color,<br>          height: lineSpacing);<br>    }<br>    <strong>return </strong>TextStyle(<br>        fontSize: finalFontsize, fontFamily: fontName, color: color);<br>  }</pre><pre><em>}</em></pre><p>if you have different base phone size just change <strong>_refrenceScreenHeight &amp; _refrenceScreenWidth </strong>as per your requirements. Now use above utilities by following :</p><pre>@override<br>Widget build(BuildContext context) {<br>  <strong>final </strong>screeSize = MediaQuery.<em>of</em>(context).<strong>size</strong>;<br>  UIUtills()<br>      .updateScreenDimesion(width: screeSize.<strong>width</strong>, height: screeSize.<strong>height</strong>);<br>}</pre><p>After updating the screen dimension follow :</p><pre>Padding(<br>  padding: EdgeInsets.only(<br>      left: UIUtills().getProportionalWidth(width: 32.0)),<br>  child: Text(<br>    <strong>&#39;Home&#39;</strong>,<br>    textAlign: TextAlign.<strong>left</strong>,<br>    style: UIUtills().getTextStyleRegular(<br>        color: Color(0xFFFFFFFF), fontName:&quot;<strong>Roboto-Medium</strong>&quot;, fontsize: 20),<br>  ),<br>)</pre><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e30218e7556" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>