<?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 Rishik on Medium]]></title>
        <description><![CDATA[Stories by Rishik on Medium]]></description>
        <link>https://medium.com/@rrishik93?source=rss-265e31ca9518------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8cqLjeI9fLFuHbeyWfHKxw.jpeg</url>
            <title>Stories by Rishik on Medium</title>
            <link>https://medium.com/@rrishik93?source=rss-265e31ca9518------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:56:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rrishik93/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[Tic Tac Toe Game with Flutter: Even a Newbie Can Make]]></title>
            <link>https://medium.com/@rrishik93/tic-tac-toe-game-with-flutter-even-a-newbie-can-make-a6fda7715e3e?source=rss-265e31ca9518------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6fda7715e3e</guid>
            <dc:creator><![CDATA[Rishik]]></dc:creator>
            <pubDate>Wed, 18 Jun 2025 05:52:34 GMT</pubDate>
            <atom:updated>2025-06-18T05:52:34.929Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we’ll guide you through creating a Tic Tac Toe game using Flutter with a sleek neumorphic design. Neumorphism uses subtle shadows and highlights for a soft, tactile look. We’ll break down the code step by step, but first, let’s cover the prerequisites to get started.</p><h3>Prerequisites:</h3><p>Before diving into the code, ensure you have the following set up:</p><ol><li><strong>Flutter SDK</strong>: Install Flutter (version 3.0 or later recommended) by following the official guide at flutter.dev. Verify the installation by running flutter doctor in your terminal.</li><li><strong>Dart</strong>: Comes bundled with Flutter, so no separate installation is needed. Ensure your IDE (e.g., VS Code or Android Studio) has the Dart plugin installed.</li><li><strong>IDE</strong>: Use an IDE like Visual Studio Code or Android Studio with Flutter and Dart plugins for a smooth development experience.</li><li><strong>Flutter Neumorphic Package</strong>: We’ll use the flutter_neumorphic_plus package for the neumorphic design. Add it to your project from pub.dev by including this in your pubspec.yaml</li><li><strong>Basic Flutter Knowledge</strong>: Familiarity with Flutter widgets, StatelessWidget, StatefulWidget, and state management will help you follow along.</li><li><strong>Device/Emulator</strong>: Set up an Android/iOS emulator or a physical device to test the app.</li></ol><pre>dependencies:<br>  flutter_neumorphic_plus: ^3.3.0</pre><p>With these prerequisites in place, let’s build the game!</p><h3>Step 1: Setting Up the Flutter App:</h3><p>We start by creating the basic structure of the Flutter app, which serves as the entry point.</p><pre>import &#39;package:flutter_neumorphic_plus/flutter_neumorphic.dart&#39;;<br><br>void main() {<br>  runApp(const TicTacToeApp());<br>}<br><br>class TicTacToeApp extends StatelessWidget {<br>  const TicTacToeApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Tic Tac Toe&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.blue,<br>      ),<br>      debugShowCheckedModeBanner: false,<br>      home: const TicTacToeScreen(),<br>    );<br>  }<br>}</pre><ul><li><strong>Importing Neumorphic Package</strong>: We import flutter_neumorphic_plus to use neumorphic UI elements for a soft, embossed look.</li><li><strong>Main Function</strong>: The main() function is the app’s entry point, launching TicTacToeApp with runApp.</li><li><strong>TicTacToeApp Widget</strong>: A StatelessWidget that sets up the MaterialApp with a title, a blue theme, no debug banner, and TicTacToeScreen as the home screen.</li></ul><h3>Step 2: Creating the Game Screen:</h3><p>The game screen is where the Tic Tac Toe board and logic live. We use a StatefulWidget to manage dynamic game state.</p><pre>class TicTacToeScreen extends StatefulWidget {<br>  const TicTacToeScreen({super.key});<br><br>  @override<br>  State&lt;TicTacToeScreen&gt; createState() =&gt; _TicTacToeScreenState();<br>}</pre><ul><li><strong>StatefulWidget</strong>: TicTacToeScreen is a StatefulWidget because the game state (board, turn, winner) changes, requiring UI updates.</li><li><strong>State Creation</strong>: The createState method links to _TicTacToeScreenState, where we define the game logic and UI.</li></ul><h3>Step 3: Managing Game State:</h3><p>In the state class, we initialize the game board, track the current turn, and manage the winner.</p><pre>class _TicTacToeScreenState extends State&lt;TicTacToeScreen&gt; {<br>  List&lt;String&gt; board = List.filled(9, &#39;&#39;);<br>  bool isXTurn = true;<br>  String winner = &#39;&#39;;</pre><ul><li><strong>Board</strong>: A list of 9 empty strings represents the 3x3 grid. Each cell holds ‘’, ‘X’, or ‘O’.</li><li><strong>isXTurn</strong>: A boolean tracking the current player, true for X, false for O.</li><li><strong>winner</strong>: A string to store the game result: ‘’ (ongoing), ‘X’, ‘O’, or ‘Draw’.</li></ul><h3>Step 4: Handling Cell Taps:</h3><p>When a player taps a cell, we update the board and switch turns.</p><pre>void onCellTap(int index) {<br>  if (board[index] == &#39;&#39; &amp;&amp; winner == &#39;&#39;) {<br>    setState(() {<br>      board[index] = isXTurn ? &#39;X&#39; : &#39;O&#39;;<br>      isXTurn = !isXTurn;<br>      checkWinner();<br>    });<br>  }<br>}</pre><ul><li><strong>onCellTap</strong>: Triggered when a cell is tapped, using the cell’s index (0–8).</li><li><strong>Conditions</strong>: Moves are allowed only if the cell is empty and no winner is declared.</li><li><strong>setState</strong>: Updates the cell with ‘X’ or ‘O’, toggles the turn, and checks for a winner.</li></ul><h3>Step 5: Checking for a Winner:</h3><p>We check for a winning combination or a draw after each move.</p><pre>void checkWinner() {<br>  const winPatterns = [<br>    [0, 1, 2], [3, 4, 5], [6, 7, 8], // Rows<br>    [0, 3, 6], [1, 4, 7], [2, 5, 8], // Columns<br>    [0, 4, 8], [2, 4, 6], // Diagonals<br>  ];<br><br>  for (var pattern in winPatterns) {<br>    if (board[pattern[0]] != &#39;&#39; &amp;&amp;<br>        board[pattern[0]] == board[pattern[1]] &amp;&amp;<br>        board[pattern[1]] == board[pattern[2]]) {<br>      setState(() {<br>        winner = board[pattern[0]];<br>      });<br>      return;<br>    }<br>  }<br><br>  if (!board.contains(&#39;&#39;)) {<br>    setState(() {<br>      winner = &#39;Draw&#39;;<br>    });<br>  }<br>}</pre><ul><li><strong>Win Patterns</strong>: Defines winning combinations (rows, columns, diagonals) using cell indices.</li><li><strong>Checking Wins</strong>: If three cells in a pattern are non-empty and match, we set winner to ‘X’ or ‘O’.</li><li><strong>Checking Draw</strong>: If the board is full and no winner is found, we set winner to ‘Draw’.</li></ul><h3>Step 6: Resetting the Game:</h3><p>A reset function clears the board for a new game.</p><pre>void resetGame() {<br>  setState(() {<br>    board = List.filled(9, &#39;&#39;);<br>    winner = &#39;&#39;;<br>    isXTurn = true;<br>  });<br>}</pre><ul><li><strong>resetGame</strong>: Resets the board, clears the winner, and sets the turn back to X, updating the UI.</li></ul><h3>Step 7: Building the UI:</h3><p>We create the visual layout using Flutter widgets and neumorphic styling.</p><pre>final baseStyle = TextStyle(<br>  fontSize: 32,<br>  fontWeight: FontWeight.bold,<br>  color: NeumorphicTheme.defaultTextColor(context),<br>);<br><br>Scaffold(<br>  backgroundColor: NeumorphicTheme.baseColor(context),<br>  appBar: AppBar(<br>    title: const Text(&#39;Neumorphic Tic Tac Toe&#39;),<br>    centerTitle: true,<br>  ),<br>  body: SingleChildScrollView(<br>    child: ConstrainedBox(<br>      constraints: BoxConstraints(<br>        minHeight: MediaQuery.of(context).size.height -<br>            kToolbarHeight -<br>            MediaQuery.of(context).padding.top,<br>      ),<br>      child: Column(<br>        mainAxisAlignment: MainAxisAlignment.center,<br>        children: [<br>          Padding(<br>            padding: const EdgeInsets.only(bottom: 16, top: 16),<br>            child: NeumorphicText(<br>              winner.isEmpty<br>                  ? &#39;Current Turn: ${isXTurn ? &#39;X&#39; : &#39;O&#39;}&#39;<br>                  : winner == &#39;Draw&#39;<br>                      ? &#39;Game Draw!&#39;<br>                      : &#39;$winner Wins!&#39;,<br>              style: const NeumorphicStyle(depth: 4),<br>              textStyle: NeumorphicTextStyle(fontSize: 28),<br>            ),<br>          ),<br>          // Grid and button code follows...<br>        ],<br>      ),<br>    ),<br>  ),<br>)</pre><ul><li><strong>Text Style</strong>: baseStyle sets a bold, large font for cell symbols, using the neumorphic theme’s text color.</li><li><strong>Scaffold</strong>: Provides the app structure with a neumorphic background and an app bar.</li><li><strong>SingleChildScrollView</strong>: Makes the content scrollable for smaller screens.</li><li><strong>ConstrainedBox</strong>: Ensures the content fills the screen height, minus the app bar and status bar.</li><li><strong>NeumorphicText</strong>: Shows the current turn or game result with a neumorphic effect.</li></ul><h3>Step 8: Creating the Game Grid:</h3><p>The 3x3 grid is built using a GridView.</p><pre>Padding(<br>  padding: const EdgeInsets.all(16.0),<br>  child: AspectRatio(<br>    aspectRatio: 1.0, // Ensure square grid<br>    child: GridView.builder(<br>      shrinkWrap: true,<br>      physics: const NeverScrollableScrollPhysics(),<br>      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(<br>        crossAxisCount: 3,<br>        crossAxisSpacing: 16,<br>        mainAxisSpacing: 16,<br>        childAspectRatio: 1.0, // Ensure square cells<br>      ),<br>      itemCount: 9,<br>      itemBuilder: (context, index) {<br>        return NeumorphicButton(<br>          onPressed: () =&gt; onCellTap(index),<br>          style: NeumorphicStyle(<br>            depth: 6,<br>            boxShape: NeumorphicBoxShape.roundRect(<br>                BorderRadius.circular(12)),<br>          ),<br>          padding: const EdgeInsets.all(8),<br>          child: Center(<br>            child: Text(<br>              board[index],<br>              style: baseStyle.copyWith(<br>                color: board[index] == &#39;X&#39; ? Colors.blue : Colors.red,<br>              ),<br>            ),<br>          ),<br>        );<br>      },<br>    ),<br>  ),<br>),</pre><ul><li><strong>AspectRatio</strong>: Keeps the grid square with a 1:1 ratio.</li><li><strong>GridView.builder</strong>: Creates a 3x3 grid with 9 cells, disabling scrolling within the grid.</li><li><strong>NeumorphicButton</strong>: Each cell is a tappable button with a neumorphic style, displaying ‘X’ (blue) or ‘O’ (red).</li></ul><h3>Step 9: Adding a Restart Button:</h3><p>A button lets players start a new game.</p><pre>NeumorphicButton(<br>  onPressed: resetGame,<br>  style: const NeumorphicStyle(<br>    depth: 4,<br>    color: Colors.blue,<br>    boxShape: NeumorphicBoxShape.stadium(),<br>  ),<br>  padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 12),<br>  child: const Text(<br>    &#39;Restart&#39;,<br>    style: TextStyle(fontSize: 18, color: Colors.white),<br>  ),<br>),</pre><ul><li><strong>NeumorphicButton</strong>: A blue, stadium-shaped button that calls resetGame when tapped.</li><li><strong>Styling</strong>: Uses white text and padding for a polished look.</li></ul><h3>Step 10: Final Touches:</h3><p>We add spacing to enhance the layout.</p><pre>const SizedBox(height: 20), // Extra padding at the bottom</pre><ul><li><strong>SizedBox</strong>: Adds vertical spacing for better visual separation.</li></ul><p><strong>Voilà! you’ve now built a Tic Tac Toe game with a modern neumorphic design using Flutter! You can extend it with features like animations, sound effects, or a score counter.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6fda7715e3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>