<?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 Burakhan Gögce on Medium]]></title>
        <description><![CDATA[Stories by Burakhan Gögce on Medium]]></description>
        <link>https://medium.com/@burakhan_gogce?source=rss-f5237dbfba12------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*57x6z9N9vwVRkdKMwlvyjA.jpeg</url>
            <title>Stories by Burakhan Gögce on Medium</title>
            <link>https://medium.com/@burakhan_gogce?source=rss-f5237dbfba12------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:03:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@burakhan_gogce/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[ Dynamically Measuring Text in Flutter with a Context-Based Extension]]></title>
            <link>https://medium.com/@burakhan_gogce/dynamically-measuring-text-in-flutter-with-a-context-based-extension-952abe899adc?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/952abe899adc</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[overflow]]></category>
            <category><![CDATA[text]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Fri, 13 Jun 2025 08:07:58 GMT</pubDate>
            <atom:updated>2025-06-13T08:07:58.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KVrqwf1HPDBiPNNk0cUj3A.png" /></figure><p>When building flexible UI layouts in Flutter, you’ll often need to know how much space a piece of text will take <strong>before</strong> rendering it. This can be critical for use cases like overflow detection, responsive widgets, or dynamic height adjustments.</p><p>In this article, I’ll show you how to create a simple but powerful Flutter extension called TextMeasurer, which allows you to <strong>measure text size dynamically</strong> using the BuildContext.</p><h3>❓ Why Measure Text Size?</h3><p>Some real-world scenarios:</p><ul><li>To check if a long title fits within a card or needs trimming</li><li>To conditionally show a “read more” icon if the text exceeds 2 lines</li><li>To calculate exact container height based on dynamic content</li><li>To support accessibility and font scaling properly</li></ul><p>For all of these, we need access to the actual rendered dimensions of a Text widget—before it’s built. That’s where this extension helps.</p><h3>🛠️ TextMeasurer Extension: Context-Aware Text Measurement</h3><p>Here’s a reusable extension you can add to any project. It attaches to BuildContext so it can access MediaQuery, theming, and layout direction.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>extension TextMeasurer on BuildContext {<br>  double measureTextHeight(<br>    String text, {<br>    TextStyle? style,<br>    int? maxLines,<br>    double maxWidth = double.infinity,<br>  }) {<br>    return _createPainter(<br>      text,<br>      style: style,<br>      maxLines: maxLines,<br>      maxWidth: maxWidth,<br>    ).size.height;<br>  }<br><br>  Size measureTextSize(<br>    String text, {<br>    TextStyle? style,<br>    int? maxLines,<br>    double maxWidth = double.infinity,<br>  }) {<br>    return _createPainter(<br>      text,<br>      style: style,<br>      maxLines: maxLines,<br>      maxWidth: maxWidth,<br>    ).size;<br>  }<br><br>  bool doesTextOverflow(<br>    String text, {<br>    TextStyle? style,<br>    int? maxLines,<br>    double maxWidth = double.infinity,<br>  }) {<br>    return _createPainter(<br>      text,<br>      style: style,<br>      maxLines: maxLines,<br>      maxWidth: maxWidth,<br>    ).didExceedMaxLines;<br>  }<br><br>  TextPainter _createPainter(<br>    String text, {<br>    TextStyle? style,<br>    int? maxLines,<br>    double maxWidth = double.infinity,<br>  }) {<br>    final defaultStyle = DefaultTextStyle.of(this).style;<br>    final effectiveStyle = style?.merge(defaultStyle) ?? defaultStyle;<br>    final scale = MediaQuery.textScalerOf(this);<br>    final direction = Directionality.of(this);<br>    return TextPainter(<br>      text: TextSpan(text: text, style: effectiveStyle),<br>      textDirection: direction,<br>      textScaler: scale,<br>      maxLines: maxLines,<br>    )..layout(maxWidth: maxWidth);<br>  }<br>}</pre><h3>✅ Real Use Case: Show an Icon If Title Overflows</h3><p>Let’s say you’re building a NewsCard widget, and you want to <strong>limit the title to 2 lines</strong>. If it overflows, you’ll show a small info icon next to it.</p><pre>class NewsCard extends StatelessWidget {<br>  final String title;<br><br>  const NewsCard({super.key, required this.title});<br>  @override<br>  Widget build(BuildContext context) {<br>    final maxWidth = MediaQuery.of(context).size.width - 48;<br>    final textStyle = Theme.of(context).textTheme.titleMedium;<br>    final isOverflowing = context.doesTextOverflow(<br>      title,<br>      style: textStyle,<br>      maxLines: 2,<br>      maxWidth: maxWidth,<br>    );<br>    return Padding(<br>      padding: const EdgeInsets.all(16),<br>      child: Row(<br>        children: [<br>          Expanded(<br>            child: Text(<br>              title,<br>              style: textStyle,<br>              maxLines: 2,<br>              overflow: TextOverflow.ellipsis,<br>            ),<br>          ),<br>          if (isOverflowing)<br>            const Padding(<br>              padding: EdgeInsets.only(left: 8),<br>              child: Icon(Icons.info_outline, size: 18, color: Colors.orange),<br>            ),<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><p>It’s clean, responsive, and now context-aware!</p><h3>🎯 When to Use TextMeasurer</h3><ul><li>To pre-calculate layout height before rendering</li><li>To conditionally render icons or buttons based on content size</li><li>To handle long text with maxLines and ellipsis logic</li><li>To support font scaling and right-to-left text direction properly</li></ul><h3>🔚 Final Thoughts</h3><p>Measuring text dynamically in Flutter gives you more control over layout decisions, especially when working with unstructured or user-generated content. With the TextMeasurer extension, you can keep your widgets responsive, accessible, and visually consistent across devices.</p><p>Copy it into your utils folder and make your layouts smarter in just a few lines.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=952abe899adc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sealed Class vs Enum: Safer and More Flexible State Management in Flutter/Dart]]></title>
            <link>https://medium.com/@burakhan_gogce/sealed-class-vs-enum-safer-and-more-flexible-state-management-in-flutter-dart-8d5dbde20dc1?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d5dbde20dc1</guid>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[sealed]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[class]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 14:58:41 GMT</pubDate>
            <atom:updated>2025-04-14T15:09:19.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6VpplUSSfE-3t_br" /></figure><p>In the Flutter/Dart world, enums represent simple, fixed sets of values, while sealed classes offer a powerful way to model richer states and behaviors. Especially when using switch-case or if-case constructs, the advantages of sealed classes become much more apparent. Below is an article explaining why we should use sealed classes instead of enums, what kind of problems this avoids, and what solutions it offers.</p><h3>1. Why Use Sealed Class Instead of Enum?</h3><h3>Limitations of Basic Enum Usage</h3><ul><li><strong>Fixed Value Set:</strong> Enums in Dart only provide constant, unchanging values. Each enum member is just a name. It cannot carry additional data or behavior.</li><li><strong>Cannot Carry Extra Info:</strong> In real applications, you often need to carry extra data alongside a state (e.g., error message, username, numeric data). Enums fall short here.</li><li><strong>Lack of Behavior:</strong> Enums are limited in terms of adding methods or different behaviors. They typically only represent a group of constants.</li></ul><h3>Strengths of Sealed Class</h3><ul><li><strong>Rich Data Modeling:</strong> Each variant of a sealed class can hold different fields. For example, a UserLoaded state can carry a username, while UserError can hold an error message.</li><li><strong>Custom Behaviors:</strong> Variants can have their own methods or behaviors.</li><li><strong>Hierarchy and Inheritance:</strong> Sealed classes allow subclasses to only extend the base class from within a specific scope (like the same file), ensuring that all possible states are known and controlled.</li><li><strong>Pattern Matching Support:</strong> When used with switch-case or if-case, sealed classes allow the compiler to verify that all possible cases are handled, making your code safer and more robust.</li></ul><h3>2. What Sealed Classes Add to Switch-Case and If-Case Structures</h3><h3>a) Compile-Time Safety</h3><p>Sealed classes ensure that switch-case expressions handle all known subclasses. When a new state is added, the compiler helps you catch any missing case statements — this enforces <strong>exhaustiveness</strong> and improves reliability.</p><h3>b) Easy Data Access via Destructuring</h3><p>With pattern matching, you can directly extract fields from sealed class variants. This makes your code more concise and readable compared to if-else chains. Example:</p><pre>sealed class UserState {}<br><br>class UserInitial extends UserState {}<br><br>class UserLoading extends UserState {}<br><br>class UserLoaded extends UserState {<br>  final String userName;<br>  UserLoaded(this.userName);<br>}<br><br>class UserError extends UserState {<br>  final String message;<br>  UserError(this.message);<br>}<br><br>void handleUserState(UserState state) {<br>  switch (state) {<br>    case UserInitial():<br>      print(&quot;Initial state.&quot;);<br>      break;<br>    case UserLoading():<br>      print(&quot;Loading user...&quot;);<br>      break;<br>    case UserLoaded(:var userName):<br>      print(&quot;User loaded: $userName&quot;);<br>      break;<br>    case UserError(:var message):<br>      print(&quot;Error: $message&quot;);<br>      break;<br>  }<br>}</pre><p>This allows you to define specific behavior for each state while accessing relevant data directly, increasing clarity.</p><h3>c) Extensibility and Modularity</h3><p>Sealed classes allow you to define logical hierarchies between states. This leads to more modular and maintainable architecture in complex applications. Each state can have its own methods, properties, and even implement interfaces — making your logic layer more flexible.</p><h3>3. What Problems Does It Prevent?</h3><ul><li><strong>Missing Case Handling:</strong> With enums, it’s easy to forget a case in a switch block. Sealed classes ensure that all cases are covered at compile time.</li><li><strong>Code Complexity and Error Risk:</strong> When additional data is needed, enums often lead to repetitive if-else blocks that are error-prone. Sealed classes reduce boilerplate and potential bugs.</li><li><strong>Maintenance Difficulty:</strong> When adding a new state, sealed classes make it easy to identify all the places that need to be updated. This ensures safer and easier code maintenance.</li></ul><h3>4. Conclusion</h3><p>In Flutter/Dart projects, enums are great for simple fixed values, but sealed classes shine when it comes to modeling complex states and behaviors. Thanks to compile-time safety, destructuring, extensibility, and modularity, sealed classes:</p><ul><li>Make your code more readable and maintainable.</li><li>Ensure all possible states are handled correctly.</li><li>Reduce bugs and improve long-term stability.</li></ul><p>For advanced state handling, error modeling, and scalable application logic, sealed classes offer a more powerful and flexible alternative to enums — making them an excellent choice for building safer, more robust Flutter/Dart applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d5dbde20dc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Separating Methods in Flutter: Techniques to Maintain Code Structure]]></title>
            <link>https://medium.com/@burakhan_gogce/separating-methods-in-flutter-techniques-to-maintain-code-structure-fc266fac635e?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc266fac635e</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Fri, 07 Mar 2025 12:44:26 GMT</pubDate>
            <atom:updated>2025-03-07T12:44:26.657Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*VtvcFYS6uGLAny0gDSZE0A.jpeg" /></figure><p>When developing applications with Flutter, having scattered methods inside a page can reduce code readability and maintainability. Managing navigation, data fetching, and user interactions all within the same file can make it difficult for new developers to understand the code and complicate future maintenance.</p><p>In this article, we’ll explore how grouping methods together and managing them separately from UI components can help create a <strong>more structured and maintainable codebase</strong>. 🚀</p><h3>Identifying the Problem</h3><p>Let’s say we have a page that contains various navigation operations, API calls, and user interactions. For example:</p><pre>class HomePage extends StatelessWidget {<br>  const HomePage({super.key});<br><br>  void navigateToDetail(BuildContext context) {<br>    Navigator.push(<br>      context,<br>      MaterialPageRoute(builder: (context) =&gt; DetailPage()),<br>    );<br>  }<br>  void fetchData() {<br>    // API call will be implemented here<br>  }<br>  void showSnackbar(BuildContext context, String message) {<br>    ScaffoldMessenger.of(context).showSnackBar(<br>      SnackBar(content: Text(message)),<br>    );<br>  }<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: Text(&quot;Home Page&quot;)),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: () =&gt; navigateToDetail(context),<br>          child: Text(&quot;Go to Detail&quot;),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h3>Refactoring Methods for Better Modularity</h3><p>To improve readability, we can separate these methods into <strong>utility/helper classes</strong> instead of keeping them inside the widget.</p><h3>1. Creating a Utility Class for Navigatio</h3><pre>class HomeDetailUtils {<br>  final BuildContext _context;<br><br>  HomeDetailUtils(this._context);<br>  void navigateToDetail() {<br>    Navigator.push(<br>      _context,<br>      MaterialPageRoute(builder: (context) =&gt; DetailPage()),<br>    );<br>  }<br>}</pre><h3>2. Separating UI and Business Logic</h3><p>Similarly, for <strong>Snackbar management</strong>, we can create a separate class:</p><pre>class SnackbarUtils {<br>  static void show(BuildContext context, String message) {<br>    ScaffoldMessenger.of(context).showSnackBar(<br>      SnackBar(content: Text(message)),<br>    );<br>  }<br>}</pre><h3>Advantages of This Approach</h3><p>✅ <strong>Improves Code Readability</strong><br>✅ <strong>Enables Code Reusability</strong><br>✅ <strong>Simplifies Maintenance</strong><br>✅ <strong>Enhances Testability</strong></p><h3>Conclusion</h3><p>By <strong>moving operations like navigation, data fetching, and Snackbar handling out of widgets into utility classes</strong>, we can make Flutter codebases more maintainable and readable.</p><p>If you want to improve your project’s structure, give this approach a try! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc266fac635e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter: Small but Annoying Keyboard Issues (TextInputAction)]]></title>
            <link>https://medium.com/@burakhan_gogce/flutter-small-but-annoying-keyboard-issues-textinputaction-5d413585fefc?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d413585fefc</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[keyboard]]></category>
            <category><![CDATA[textformfield]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[textfield]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Fri, 28 Feb 2025 08:55:38 GMT</pubDate>
            <atom:updated>2025-02-28T08:55:38.682Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CET0FktMW4_yHnl0.jpg" /></figure><p>In daily life, we often encounter small but annoying keyboard and form field issues while using banking, e-commerce, or messaging apps. Sometimes, we struggle to navigate between form fields smoothly, and other times, we waste time due to the wrong keyboard type. As Flutter developers, we sometimes make similar mistakes without realizing it, ultimately worsening the user experience.</p><p>This article will explore <strong>textInputAction</strong> values in detail and explain when and how to use them effectively.</p><h3>2. Available textInputAction Values and Their Use Cases</h3><p>Flutter provides multiple <strong>textInputAction</strong> values, each with a specific purpose. Here are the most commonly used ones and their practical applications:</p><h3>1. TextInputAction.none</h3><ul><li>Removes any action button from the keyboard.</li><li>Use case: When you don’t want any interaction from the “Enter” key.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.none,<br>),</pre><h3>2. TextInputAction.unspecified</h3><ul><li>Uses the platform’s default behavior.</li><li>Use case: When you want the keyboard to behave as the operating system determines.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.unspecified,<br>),</pre><h3>3. TextInputAction.done</h3><ul><li>Closes the keyboard when pressed.</li><li>Use case: Typically used for the last field in a form.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.done,<br>),</pre><h3>4. TextInputAction.go</h3><ul><li>Triggers an action like login or search.</li><li>Use case: Login forms where pressing “Enter” should execute a function.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.go,<br>  onSubmitted: (value) {<br>    print(&#39;Logging in...&#39;);<br>  },<br>),</pre><h3>5. TextInputAction.next</h3><ul><li>Moves to the next input field.</li><li>Use case: Forms with multiple input fields.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.next,<br>),</pre><h3>6. TextInputAction.previous</h3><ul><li>Moves the focus to the previous field.</li><li>Use case: When navigating backward in a multi-field form.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.previous,<br>),</pre><h3>7. TextInputAction.search</h3><ul><li>Displays a search button on the keyboard.</li><li>Use case: Search fields where pressing “Enter” should initiate a search.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.search,<br>  onSubmitted: (value) {<br>    print(&#39;Searching: $value&#39;);<br>  },<br>),</pre><h3>8. TextInputAction.send</h3><ul><li>Displays a send button and triggers a sending action.</li><li>Use case: Messaging apps where pressing “Enter” should send the message.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.send,<br>  onSubmitted: (value) {<br>    print(&#39;Message sent: $value&#39;);<br>  },<br>),</pre><h3>9. TextInputAction.newline</h3><ul><li>Inserts a new line instead of submitting.</li><li>Use case: Multiline text fields like comments or notes.</li></ul><pre>TextField(<br>  textInputAction: TextInputAction.newline,<br>  keyboardType: TextInputType.multiline,<br>  maxLines: null,<br>),</pre><h3>3. Practical Use Cases for textInputAction</h3><h3>3.1. Multi-step Forms (TextInputAction.next &amp; TextInputAction.done)</h3><p>When filling out a form, users should be able to press “Enter” to move to the next field. The last field should close the keyboard upon pressing “Enter.”</p><pre>TextFormField(<br>  decoration: InputDecoration(labelText: &#39;First Name&#39;),<br>  textInputAction: TextInputAction.next,<br>),<br>TextFormField(<br>  decoration: InputDecoration(labelText: &#39;Last Name&#39;),<br>  textInputAction: TextInputAction.next,<br>),<br>TextFormField(<br>  decoration: InputDecoration(labelText: &#39;Email&#39;),<br>  keyboardType: TextInputType.emailAddress,<br>  textInputAction: TextInputAction.done,<br>),</pre><p>Here, pressing <strong>Enter</strong> moves the focus to the next field, and the keyboard closes after the last field.</p><h3>3.2. Search Bar (TextInputAction.search)</h3><p>In a search bar, it’s better to replace the “Enter” key with a <strong>Search</strong> button.</p><pre>TextField(<br>  decoration: InputDecoration(<br>    labelText: &#39;Search&#39;,<br>    suffixIcon: Icon(Icons.search),<br>  ),<br>  textInputAction: TextInputAction.search,<br>  onSubmitted: (value) {<br>    print(&#39;Searching for: $value&#39;);<br>  },<br>),</pre><p>When the user presses <strong>Enter</strong>, the search function gets triggered.</p><h3>3.3. Login Forms (TextInputAction.go)</h3><p>For login forms, the “Enter” key should trigger the login action. Using <strong>TextInputAction.go</strong>, we can achieve this behavior.</p><pre>TextField(<br>  decoration: InputDecoration(labelText: &#39;Username&#39;),<br>  textInputAction: TextInputAction.go,<br>  onSubmitted: (value) {<br>    print(&#39;Logging in...&#39;);<br>  },<br>),</pre><p>Pressing <strong>Enter</strong> here can directly call a login function.</p><h3>3.4. Multiline Text Fields (TextInputAction.newline)</h3><p>When dealing with long text fields (e.g., comments or messages), pressing “Enter” should create a new line instead of submitting the form.</p><pre>TextField(<br>  decoration: InputDecoration(labelText: &#39;Write your comment&#39;),<br>  textInputAction: TextInputAction.newline,<br>  keyboardType: TextInputType.multiline,<br>  maxLines: null,<br>),</pre><p>Now, pressing <strong>Enter</strong> will add a new line instead of closing the keyboard.</p><h3>3.5. Messaging Apps (TextInputAction.send)</h3><p>For messaging apps or email fields, <strong>TextInputAction.send</strong> allows the keyboard to display a <strong>Send</strong> button instead of “Enter.”</p><pre>TextField(<br>  decoration: InputDecoration(labelText: &#39;Type your message&#39;),<br>  textInputAction: TextInputAction.send,<br>  onSubmitted: (value) {<br>    print(&#39;Message sent: $value&#39;);<br>  },<br>),</pre><p>Now, pressing <strong>Enter</strong> will send the message instead of inserting a new line.</p><h3>Conclsion</h3><p><strong>textInputAction</strong> is an often-overlooked feature in Flutter, but it significantly improves user experience when used correctly. Instead of defaulting to <strong>TextInputAction.next</strong> and <strong>TextInputAction.done</strong>, developers should consider using <strong>search, go, send, previous, and newline</strong> where applicable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d413585fefc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Tell If We’re Writing Bad Code?]]></title>
            <link>https://medium.com/@burakhan_gogce/how-to-tell-if-were-writing-bad-code-b365793052d6?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/b365793052d6</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Wed, 26 Feb 2025 19:12:20 GMT</pubDate>
            <atom:updated>2025-02-26T19:12:20.748Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qOMfJps6Ug01VWKb.jpg" /></figure><h3>Introduction</h3><p>Sometimes, we think we’ve written something brilliant, but when we look at it a few days later, we can’t even understand it ourselves. Here are some signs that we might be writing bad code!</p><h3>1. If We Can’t Even Understand Our Own Code 🤔</h3><p>If you open your code after a few days and think, “Who wrote this?” — spoiler alert, it was you. If you can’t understand your own code, expecting others to understand it is wishful thinking.<br><strong>Solution:</strong> Use meaningful variable names and avoid unnecessary complexity.</p><h3>2. If We Keep Copy-Pasting Code 🔄</h3><p>If you copy a function and just change a few lines over and over again, that’s a sign of bad code.<br><strong>Solution:</strong> Follow the DRY (Don’t Repeat Yourself) principle and refactor common logic into reusable functions.</p><h3>3. If We Keep Saying “I’ll Fix This Later” ⏳</h3><p>Every time we say, “Let’s leave it like this for now, I’ll clean it up later,” we’re actually accumulating technical debt that will probably never be repaid.<br><strong>Solution:</strong> Refactor your code regularly, even with small improvements.</p><h3>4. If a Small Change Breaks the Whole System 💥</h3><p>If tweaking a single line of code unexpectedly causes failures elsewhere, your codebase is not as stable as it should be.<br><strong>Solution:</strong> Make your code more modular, reduce dependencies, and write tests.</p><h3>5. If Our Functions and Classes Are Turning Into Monsters 👾</h3><p>If a function or class has more than 100 lines and is trying to do everything at once, it’s a red flag.<br><strong>Solution:</strong> Apply SOLID principles and ensure that each function or class has a single responsibility.</p><h3>6. If Our Error Messages Are Like Cryptic Riddles 🔐</h3><p>If you see something like “Exception: Something went wrong” and have to play detective to figure out what happened, your code lacks clarity.<br><strong>Solution:</strong> Write meaningful error messages and improve logging.</p><h3>7. If Our Teammates Have a Meltdown While Reading Our Code 🤯</h3><p>If code reviews are filled with comments like, “What does this do?” or “Can we make this more readable?”, it’s time to rethink your approach.<br><strong>Solution:</strong> Optimize for the reader, not the writer. Write clean, easy-to-understand code.</p><h3>Conclusion</h3><p>We all write bad code sometimes, but the key is to recognize it and improve. If you spot any of these signs in your code, it’s time for a refactor session! 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b365793052d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hiding Flutter Widgets When the App Goes to Background]]></title>
            <link>https://medium.com/@burakhan_gogce/hiding-flutter-widgets-when-the-app-goes-to-background-60f5d9ac432b?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/60f5d9ac432b</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Sat, 15 Feb 2025 13:16:36 GMT</pubDate>
            <atom:updated>2025-02-15T13:16:36.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C-wDECrjegmbUbJL.jpg" /></figure><h3>Introduction</h3><p>In many applications, protecting sensitive content when the app goes to the background is crucial. To enhance user privacy and prevent sensitive information from being unintentionally visible, certain widgets may need to be blurred or completely hidden when the app is inactive.</p><p>In this article, we will show you how to develop a feature in Flutter that automatically blurs or masks widgets when the app goes to the background.</p><h3>How Does the Widget Work?</h3><p>This feature wraps your widgets and listens to the app’s lifecycle state (e.g., when the app becomes inactive or moves to the background). When triggered, it overlays your widget with a blur effect or a masking layer.</p><p>This solution is fully customizable and can be easily applied to any widget of your choice.</p><h3>Step 1: Creating the Extension</h3><p>First, we create an extension method for all widgets. This extension allows us to dynamically add blur or masking functionality.</p><pre>import &#39;dart:ui&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br><br>/// An extension to protect widgets when the app goes inactive or to the background.<br>extension HideBackgroundWidget on Widget {<br>  Widget hideBackgroundWidget({<br>    Color overlayColor = Colors.black,<br>    double opacity = 0.8,<br>    bool blurEffect = true,<br>    Widget? overlayWidget,<br>  }) {<br>    return _HideBackgroundWrapper(<br>      child: this,<br>      overlayColor: overlayColor,<br>      opacity: opacity,<br>      blurEffect: blurEffect,<br>      overlayWidget: overlayWidget,<br>    );<br>  }<br>}</pre><p>This extension wraps existing widgets, adding an extra protective layer to them.</p><h3>Step 2: Creating the Wrapper Widget</h3><p>Now, we create a widget called _HideBackgroundWrapper. This widget listens to the app’s lifecycle and blurs or hides the widget when it becomes inactive or moves to the background.</p><pre>class _HideBackgroundWrapper extends StatefulWidget {<br>  final Widget child;<br>  final Color overlayColor;<br>  final double opacity;<br>  final bool blurEffect;<br>  final Widget? overlayWidget;<br><br>  const _HideBackgroundWrapper({<br>    required this.child,<br>    this.overlayColor = Colors.black,<br>    this.opacity = 0.8,<br>    this.blurEffect = true,<br>    this.overlayWidget,<br>  });<br><br>  @override<br>  State&lt;_HideBackgroundWrapper&gt; createState() =&gt; _HideBackgroundWrapperState();<br>}<br><br>class _HideBackgroundWrapperState extends State&lt;_HideBackgroundWrapper&gt; with WidgetsBindingObserver {<br>  bool _isBlurred = false;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    WidgetsBinding.instance.addObserver(this);<br>  }<br><br>  @override<br>  void didChangeAppLifecycleState(AppLifecycleState state) {<br>    setState(() {<br>      _isBlurred = state == AppLifecycleState.paused || state == AppLifecycleState.inactive;<br>    });<br>  }<br><br>  @override<br>  void dispose() {<br>    WidgetsBinding.instance.removeObserver(this);<br>    super.dispose();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Stack(<br>      alignment: Alignment.center,<br>      children: [<br>        widget.child,<br>        if (_isBlurred)<br>          Positioned.fill(<br>            child: widget.blurEffect<br>                ? BackdropFilter(<br>                    filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),<br>                    child: Container(<br>                      color: widget.overlayColor.withOpacity(widget.opacity),<br>                      alignment: Alignment.center,<br>                      child: widget.overlayWidget ?? const SizedBox(),<br>                    ),<br>                  )<br>                : Container(<br>                    color: widget.overlayColor.withOpacity(widget.opacity),<br>                    alignment: Alignment.center,<br>                    child: widget.overlayWidget ?? const SizedBox(),<br>                  ),<br>          ),<br>      ],<br>    );<br>  }<br>}</pre><h3>Step 3: Using the Widget</h3><p>Now, you can easily use this extension to protect your widgets. Here is an example:</p><pre>Container(<br>  color: Colors.blue,<br>  padding: const EdgeInsets.all(20),<br>  child: const Text(&#39;This widget will be hidden or blurred!&#39;),<br>).hideBackgroundWidget(<br>  overlayColor: Colors.red,<br>  blurEffect: true,<br>  overlayWidget: const Icon(Icons.lock, size: 50, color: Colors.white),<br>);</pre><p>This code will automatically blur or hide the wrapped widget when the app goes to the background.</p><h3>Conclusion</h3><p>The hideBackgroundWidget feature is a powerful and easy-to-implement solution for protecting sensitive data in Flutter applications. This feature enhances user privacy and provides a better overall experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60f5d9ac432b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Open/Closed Principle (OCP)? Examples with Flutter and Dart]]></title>
            <link>https://medium.com/@burakhan_gogce/what-is-open-closed-principle-ocp-examples-with-flutter-and-dart-b79b0c34aafb?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/b79b0c34aafb</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Fri, 17 Jan 2025 06:17:10 GMT</pubDate>
            <atom:updated>2025-01-17T06:17:10.400Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2lFEyTae_RG2_nIJKYZw5w.png" /></figure><h3>What is Open/Closed Principle (OCP)? SOLID Principles with Flutter and Dart</h3><p>The <strong>Open/Closed Principle (OCP)</strong> is the third of the <strong>SOLID principles</strong> and aims to enhance extensibility while minimizing the need for modifications. What exactly does OCP mean, and how can we implement it in Flutter/Dart projects? Let’s dive in! 🚀</p><h3>What is OCP?</h3><p>The core idea of OCP is:</p><blockquote><em>“Software entities (classes, modules, functions) should be open for extension but closed for modification.”</em></blockquote><p>In simpler terms, you should be able to add new functionality to a class without altering its existing code.</p><h3>Why is OCP Important?</h3><ul><li><strong>Ease of Extensibility:</strong> New features can be added without modifying existing code.</li><li><strong>Reduced Risk of Bugs:</strong> Avoiding changes to existing code reduces the risk of introducing bugs.</li><li><strong>Increased Flexibility:</strong> Your code becomes modular and easier to scale.</li></ul><h3>Examples of OCP with Flutter and Dart</h3><h4>1️⃣ Example Violating OCP</h4><pre>class PaymentProcessor {<br>  void processPayment(String paymentType) {<br>    if (paymentType == &quot;credit_card&quot;) {<br>      print(&quot;Processing credit card payment...&quot;);<br>    } else if (paymentType == &quot;paypal&quot;) {<br>      print(&quot;Processing PayPal payment...&quot;);<br>    } else {<br>      throw Exception(&quot;Unknown payment type!&quot;);<br>    }<br>  }<br>}</pre><p><strong>Problem:</strong> Adding a new payment method requires modifying the processPayment method. This violates OCP.</p><h4>2️⃣ Correct Implementation of OCP</h4><p>To fix this, you can define each payment method in its own class and use a common interface:</p><pre>abstract class PaymentMethod {<br>  void processPayment();<br>}<br><br>class CreditCardPayment implements PaymentMethod {<br>  @override<br>  void processPayment() {<br>    print(&quot;Processing credit card payment...&quot;);<br>  }<br>}<br><br>class PayPalPayment implements PaymentMethod {<br>  @override<br>  void processPayment() {<br>    print(&quot;Processing PayPal payment...&quot;);<br>  }<br>}<br><br>class PaymentProcessor {<br>  void processPayment(PaymentMethod paymentMethod) {<br>    paymentMethod.processPayment();<br>  }<br>}<br><br>void main() {<br>  PaymentProcessor processor = PaymentProcessor();<br>  PaymentMethod creditCard = CreditCardPayment();<br>  PaymentMethod paypal = PayPalPayment();<br>  processor.processPayment(creditCard);<br>  processor.processPayment(paypal);<br>}</pre><p><strong>Solution:</strong> To add a new payment method, you only need to create a new class without altering existing code.</p><h3>Applying OCP in Flutter</h3><h4>OCP in Widget Design</h4><p>Imagine you have different types of buttons in a Flutter app. You can create a structure that adheres to OCP:</p><pre>abstract class CustomButton {<br>  Widget render();<br>}<br><br>class PrimaryButton implements CustomButton {<br>  @override<br>  Widget render() {<br>    return ElevatedButton(<br>      onPressed: () {},<br>      child: Text(&quot;Primary Button&quot;),<br>    );<br>  }<br>}<br><br>class SecondaryButton implements CustomButton {<br>  @override<br>  Widget render() {<br>    return OutlinedButton(<br>      onPressed: () {},<br>      child: Text(&quot;Secondary Button&quot;),<br>    );<br>  }<br>}<br><br>class ButtonRenderer {<br>  void renderButton(CustomButton button) {<br>    runApp(MaterialApp(home: Scaffold(body: Center(child: button.render()))));<br>  }<br>}<br><br>void main() {<br>  ButtonRenderer renderer = ButtonRenderer();<br>  CustomButton primaryButton = PrimaryButton();<br>  CustomButton secondaryButton = SecondaryButton();<br>  renderer.renderButton(primaryButton);<br>  renderer.renderButton(secondaryButton);<br>}</pre><p><strong>Advantage:</strong> Adding a new button type only requires creating a new class. There’s no need to modify the existing ButtonRenderer logic.</p><h3>Advantages of Using OCP</h3><p>1️⃣ <strong>Flexibility:</strong> Extend functionality without altering the current structure.<br>2️⃣ <strong>Modularity:</strong> New features can be added as independent modules.<br>3️⃣ <strong>Reduced Risk:</strong> Existing functionality remains intact, reducing the chance of introducing bugs.</p><h3>Conclusion:</h3><p>The <strong>Open/Closed Principle (OCP)</strong> helps create extensible, flexible, and robust code structures in Flutter projects. By adhering to OCP, your codebase will be ready to handle both current requirements and future expansions seamlessly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b79b0c34aafb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Open/Closed Principle (OCP) Nedir? Flutter/Dart ile SOLID Prensipleri]]></title>
            <link>https://medium.com/@burakhan_gogce/open-closed-principle-ocp-nedir-flutter-dart-ile-solid-prensipleri-5a90918e343a?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a90918e343a</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[solid]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Fri, 17 Jan 2025 06:16:59 GMT</pubDate>
            <atom:updated>2025-01-17T06:16:59.881Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2lFEyTae_RG2_nIJKYZw5w.png" /></figure><p><strong>Open/Closed Principle (OCP)</strong>, <strong>SOLID prensiplerinin üçüncüsü</strong> olup yazılım tasarımında genişletilebilirliği artırmayı ve değişiklik gereksinimlerini azaltmayı hedefler. Peki, OCP tam olarak nedir ve Flutter/Dart projelerinde nasıl uygulanır? Gelin birlikte inceleyelim! 🚀</p><h3>OCP Nedir?</h3><p>OCP’nin temel felsefesi şudur:</p><blockquote><em>“Bir yazılım varlığı (sınıf, modül, fonksiyon), genişletmeye açık ancak değişikliğe kapalı olmalıdır.”</em></blockquote><p>Başka bir deyişle, mevcut bir sınıfın davranışını değiştirmek zorunda kalmadan, yeni işlevsellik ekleyebilmelisiniz.</p><h3>OCP Neden Önemlidir?</h3><ul><li><strong>Kolay Genişletilebilirlik:</strong> Yeni özellikler eklerken mevcut kodu değiştirmek gerekmez.</li><li><strong>Daha Az Hata Riski:</strong> Mevcut kodu değiştirmeden genişletmek, var olan işlevselliği bozma riskini azaltır.</li><li><strong>Yüksek Esneklik:</strong> Kodunuz daha modüler hale gelir ve ölçeklenebilirliği artar.</li></ul><h3>Flutter ve Dart ile OCP Örnekleri</h3><h4>1️⃣ OCP’yi İhlal Eden Bir Örnek</h4><pre>class PaymentProcessor {<br>  void processPayment(String paymentType) {<br>    if (paymentType == &quot;credit_card&quot;) {<br>      print(&quot;Processing credit card payment...&quot;);<br>    } else if (paymentType == &quot;paypal&quot;) {<br>      print(&quot;Processing PayPal payment...&quot;);<br>    } else {<br>      throw Exception(&quot;Unknown payment type!&quot;);<br>    }<br>  }<br>}</pre><p><strong>Problem:</strong> Yeni bir ödeme yöntemi eklemek için, processPayment metodunu değiştirmek zorundayız. Bu, OCP’nin ihlal edildiği anlamına gelir.</p><h4>2️⃣ OCP’ye Uygun Bir Çözüm</h4><p>Bu sorunu çözmek için, her ödeme yöntemini kendi sınıfında tanımlayabilir ve ortak bir arayüzle kullanabiliriz:</p><pre>abstract class PaymentMethod {<br>  void processPayment();<br>}<br><br>class CreditCardPayment implements PaymentMethod {<br>  @override<br>  void processPayment() {<br>    print(&quot;Processing credit card payment...&quot;);<br>  }<br>}<br><br>class PayPalPayment implements PaymentMethod {<br>  @override<br>  void processPayment() {<br>    print(&quot;Processing PayPal payment...&quot;);<br>  }<br>}<br><br>class PaymentProcessor {<br>  void processPayment(PaymentMethod paymentMethod) {<br>    paymentMethod.processPayment();<br>  }<br>}<br><br>void main() {<br>  PaymentProcessor processor = PaymentProcessor();<br>  PaymentMethod creditCard = CreditCardPayment();<br>  PaymentMethod paypal = PayPalPayment();<br>  processor.processPayment(creditCard);<br>  processor.processPayment(paypal);<br>}</pre><p><strong>Çözüm:</strong> Yeni bir ödeme yöntemi eklemek istediğinizde, sadece yeni bir sınıf oluşturmanız yeterlidir. Mevcut kodu değiştirmeye gerek kalmaz.</p><h3>Flutter’da OCP Kullanımı</h3><h4>Widget Tasarımında OCP</h4><p>Bir Flutter uygulamasında farklı türde butonlar olduğunu düşünelim. Her buton türü için ortak bir yapı kullanabiliriz:</p><pre>abstract class CustomButton {<br>  Widget render();<br>}<br><br>class PrimaryButton implements CustomButton {<br>  @override<br>  Widget render() {<br>    return ElevatedButton(<br>      onPressed: () {},<br>      child: Text(&quot;Primary Button&quot;),<br>    );<br>  }<br>}<br><br>class SecondaryButton implements CustomButton {<br>  @override<br>  Widget render() {<br>    return OutlinedButton(<br>      onPressed: () {},<br>      child: Text(&quot;Secondary Button&quot;),<br>    );<br>  }<br>}<br><br>class ButtonRenderer {<br>  void renderButton(CustomButton button) {<br>    runApp(MaterialApp(home: Scaffold(body: Center(child: button.render()))));<br>  }<br>}<br><br>void main() {<br>  ButtonRenderer renderer = ButtonRenderer();<br>  CustomButton primaryButton = PrimaryButton();<br>  CustomButton secondaryButton = SecondaryButton();<br>  renderer.renderButton(primaryButton);<br>  renderer.renderButton(secondaryButton);<br>}</pre><p><strong>Avantaj:</strong> Yeni bir buton türü eklemek istediğinizde, sadece yeni bir sınıf oluşturmanız yeterlidir. Mevcut ButtonRenderer kodunu değiştirmek zorunda kalmazsınız.</p><h3>OCP Kullanmanın Avantajları</h3><p>1️⃣ <strong>Esneklik:</strong> Kodunuzu mevcut yapıdan ödün vermeden genişletebilirsiniz.<br>2️⃣ <strong>Modülerlik:</strong> Her yeni özellik, bağımsız bir modül olarak eklenebilir.<br>3️⃣ <strong>Daha Az Hata:</strong> Mevcut kodu değiştirmek yerine genişletmek, var olan işlevselliği korur.</p><h3>Sonuç:</h3><p><strong>Open/Closed Principle (OCP)</strong>, Flutter projelerinde daha genişletilebilir, esnek ve hataya dayanıklı bir yapı oluşturmanın anahtarıdır. Bu prensibi takip ederek kodunuzu hem şu anki ihtiyaçlara hem de gelecekteki genişlemelere hazır hale getirebilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a90918e343a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Single Responsibility Principle (SRP)? SOLID Principles with Flutter and Dart]]></title>
            <link>https://medium.com/@burakhan_gogce/what-is-single-responsibility-principle-srp-solid-principles-with-flutter-and-dart-cbfbb9f466c1?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbfbb9f466c1</guid>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Fri, 17 Jan 2025 06:16:54 GMT</pubDate>
            <atom:updated>2025-01-17T06:16:54.230Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Seb9s0HDVVFmxX_kX12kBg.png" /></figure><p>The <strong>Single Responsibility Principle (SRP)</strong> is the first of the <strong>SOLID principles</strong>, and it lays the foundation for writing clean, maintainable, and readable code. But what exactly is SRP, and how can we implement it in Flutter/Dart projects? Let’s explore! 🚀</p><h3>What is SRP?</h3><p>The core idea of SRP is:</p><blockquote><em>“A class should have only one reason to change.”</em></blockquote><p>In simpler terms, a class should do <strong>one thing</strong> only. If a class is responsible for multiple things, it increases complexity and makes maintenance difficult.</p><h3>Why is SRP Important?</h3><ul><li><strong>Readable Code:</strong> Classes are easier to understand when they serve a single purpose.</li><li><strong>Easier Maintenance:</strong> Changes can be localized to the relevant class.</li><li><strong>Fewer Bugs:</strong> Combining multiple responsibilities increases the chance of errors.</li></ul><h3>Examples of SRP with Flutter and Dart</h3><h4>1️⃣ Example Violating SRP</h4><pre>class UserManager {<br>  void saveUser(String user) {<br>    print(&quot;Saving user: $user&quot;);<br>  }<br><br>  void sendEmail(String user) {<br>    print(&quot;Sending email to: $user&quot;);<br>  }<br><br>  void logActivity(String activity) {<br>    print(&quot;Logging activity: $activity&quot;);<br>  }<br>}</pre><p><strong>Problem:</strong> The UserManager class handles saving users, sending emails, and logging activities. This violates SRP because the class has multiple responsibilities.</p><h4>2️⃣ Correct Implementation of SRP</h4><p>We can split this class into separate classes, each handling a single responsibility:</p><pre>class UserRepository {<br>  void saveUser(String user) {<br>    print(&quot;Saving user: $user&quot;);<br>  }<br>}<br><br>class EmailService {<br>  void sendEmail(String user) {<br>    print(&quot;Sending email to: $user&quot;);<br>  }<br>}<br><br>class ActivityLogger {<br>  void logActivity(String activity) {<br>    print(&quot;Logging activity: $activity&quot;);<br>  }<br>}</pre><p><strong>Solution:</strong> Each class now has a single responsibility. This structure makes your code cleaner and more maintainable.</p><h3>Applying SRP in Flutter</h3><h4>SRP in Widget Design</h4><p>In Flutter, applying SRP to widgets ensures that your UI code is clean and maintainable. For example:</p><pre>class UserProfile extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Column(<br>      children: [<br>        UserAvatar(),<br>        UserDetails(),<br>        UserActions(),<br>      ],<br>    );<br>  }<br>}<br><br>class UserAvatar extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return CircleAvatar(<br>      radius: 50,<br>      backgroundImage: AssetImage(&#39;assets/avatar.png&#39;),<br>    );<br>  }<br>}<br><br>class UserDetails extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Text(<br>      &quot;John Doe&quot;,<br>      style: TextStyle(fontSize: 20),<br>    );<br>  }<br>}<br><br>class UserActions extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Row(<br>      mainAxisAlignment: MainAxisAlignment.spaceAround,<br>      children: [<br>        IconButton(onPressed: () {}, icon: Icon(Icons.message)),<br>        IconButton(onPressed: () {}, icon: Icon(Icons.call)),<br>      ],<br>    );<br>  }<br>}</pre><p>Here:</p><ul><li>UserAvatar handles only the avatar display.</li><li>UserDetails is responsible for showing user information.</li><li>UserActions manages user-related actions.</li></ul><p>Each widget has a single responsibility, adhering to SRP.</p><h3>Advantages of Using SRP</h3><p>1️⃣ <strong>Improved Readability:</strong> Each class or widget does only one thing, making the code easier to understand.<br>2️⃣ <strong>Simpler Maintenance:</strong> Changes are isolated to the relevant class or widget.<br>3️⃣ <strong>Reduced Dependencies:</strong> By separating responsibilities, dependencies are minimized, simplifying testing.</p><h3>Conclusion:</h3><p>The <strong>Single Responsibility Principle (SRP)</strong> is crucial for creating clean, organized, and maintainable code in Flutter projects. By designing your classes and widgets to follow this principle, you’ll have a codebase that’s easier to work with and more resistant to bugs in the long run.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbfbb9f466c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Single Responsibility Principle (SRP) Nedir? Flutter/Dart ile SOLID Prensipleri]]></title>
            <link>https://medium.com/@burakhan_gogce/single-responsibility-principle-srp-nedir-flutter-dart-ile-solid-prensipleri-f3c33b7cb8e9?source=rss-f5237dbfba12------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3c33b7cb8e9</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Burakhan Gögce]]></dc:creator>
            <pubDate>Thu, 16 Jan 2025 05:37:06 GMT</pubDate>
            <atom:updated>2025-01-16T06:24:24.988Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Seb9s0HDVVFmxX_kX12kBg.png" /></figure><p><strong>Single Responsibility Principle (SRP)</strong>, <strong>SOLID prensiplerinin ilki</strong> olup yazılım tasarımında temiz, sürdürülebilir ve okunabilir bir yapı oluşturmanın temel taşlarından biridir. Peki, SRP nedir ve Flutter/Dart projelerinde nasıl uygulanır? Detaylara birlikte bakalım! 🚀</p><h3>SRP Nedir?</h3><p>SRP’nin temel ilkesi şudur:</p><blockquote><em>“Bir sınıfın yalnızca bir sorumluluğu olmalıdır ve bu sorumluluk yalnızca bir sebebe bağlı olarak değişmelidir.”</em></blockquote><p>Başka bir deyişle, bir sınıf yalnızca <strong>tek bir iş</strong> yapmalıdır. Eğer bir sınıf birden fazla sorumluluğu üstleniyorsa, bu durum kodun karmaşıklığını artırır ve bakımını zorlaştırır.</p><h3>SRP Neden Önemlidir?</h3><ul><li><strong>Kolay Anlaşılır Kod:</strong> Sınıflar yalnızca bir amaca hizmet ettiği için daha okunabilir olur.</li><li><strong>Kolay Bakım:</strong> Bir değişiklik gerektiğinde, yalnızca ilgili sınıfı güncellemeniz yeterlidir.</li><li><strong>Daha Az Hata:</strong> Birden fazla sorumluluğun bir sınıfta toplanması, hataların oluşma riskini artırır.</li></ul><h3>Flutter ve Dart ile SRP Örnekleri</h3><h4>1️⃣ SRP’yi İhlal Eden Bir Örnek</h4><pre>class UserManager {<br>  void saveUser(String user) {<br>    print(&quot;Saving user: $user&quot;);<br>  }<br><br>  void sendEmail(String user) {<br>    print(&quot;Sending email to: $user&quot;);<br>  }<br><br>  void logActivity(String activity) {<br>    print(&quot;Logging activity: $activity&quot;);<br>  }<br>}</pre><p><strong>Problem:</strong> UserManager sınıfı, kullanıcıyı kaydetme, e-posta gönderme ve aktivite kaydı gibi farklı sorumlulukları üstleniyor. Bu, SRP’nin ihlal edildiği anlamına gelir.</p><h4>2️⃣ SRP’ye Uygun Bir Çözüm</h4><p>Bu sınıfı, her bir sorumluluk için ayrı sınıflara bölebiliriz:</p><pre>class UserRepository {<br>  void saveUser(String user) {<br>    print(&quot;Saving user: $user&quot;);<br>  }<br>}<br><br>class EmailService {<br>  void sendEmail(String user) {<br>    print(&quot;Sending email to: $user&quot;);<br>  }<br>}<br><br>class ActivityLogger {<br>  void logActivity(String activity) {<br>    print(&quot;Logging activity: $activity&quot;);<br>  }<br>}</pre><p><strong>Çözüm:</strong> Artık her sınıf yalnızca tek bir sorumluluğa sahip. Bu yapı, kodunuzu daha düzenli ve yönetilebilir hale getirir.</p><h3>Flutter’da SRP Kullanımı</h3><h4>Widget Tasarımında SRP</h4><p>Flutter’da SRP’yi widget’lar arasında uygulamak, UI kodunuzun temiz ve sürdürülebilir olmasını sağlar. Örneğin:</p><pre>class UserProfile extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Column(<br>      children: [<br>        UserAvatar(),<br>        UserDetails(),<br>        UserActions(),<br>      ],<br>    );<br>  }<br>}<br><br>class UserAvatar extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return CircleAvatar(<br>      radius: 50,<br>      backgroundImage: AssetImage(&#39;assets/avatar.png&#39;),<br>    );<br>  }<br>}<br><br>class UserDetails extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Text(<br>      &quot;John Doe&quot;,<br>      style: TextStyle(fontSize: 20),<br>    );<br>  }<br>}<br><br>class UserActions extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Row(<br>      mainAxisAlignment: MainAxisAlignment.spaceAround,<br>      children: [<br>        IconButton(onPressed: () {}, icon: Icon(Icons.message)),<br>        IconButton(onPressed: () {}, icon: Icon(Icons.call)),<br>      ],<br>    );<br>  }<br>}</pre><p>Bu yapıda:</p><ul><li>UserAvatar yalnızca avatarı gösterir.</li><li>UserDetails kullanıcı bilgilerini gösterir.</li><li>UserActions kullanıcıyla ilgili eylemleri yönetir.</li></ul><p>Her widget’ın yalnızca bir sorumluluğu vardır ve bu, SRP’ye uygun bir tasarımdır.</p><h3>SRP Kullanmanın Avantajları</h3><p>1️⃣ <strong>Kod Okunabilirliği:</strong> Her sınıf veya widget yalnızca bir işi yaptığı için kod daha kolay anlaşılır.<br>2️⃣ <strong>Kolay Değişiklik:</strong> Bir değişiklik gerektiğinde, yalnızca ilgili sınıfı veya widget’ı güncellemeniz yeterlidir.<br>3️⃣ <strong>Daha Az Bağımlılık:</strong> Her sorumluluğun ayrı bir sınıfa ait olması, bağımlılıkları azaltır ve test süreçlerini kolaylaştırır.</p><h3>Sonuç:</h3><p><strong>Single Responsibility Principle (SRP)</strong>, Flutter projelerinde kodunuzu daha temiz, düzenli ve sürdürülebilir hale getirmek için temel bir prensiptir. Sınıflarınızı ve widget’larınızı bu prensibe uygun tasarlayarak uzun vadede daha kolay bakım yapılabilir ve hataya daha dayanıklı bir kod yapısı elde edebilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3c33b7cb8e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>