1

I have read this word 'boilerplate' in many documents (like equatable plugin in flutter) but don't know what does it mean..! very confused , I thought boilerplate is preparation for code before running the application (like we prepare stuff before cooking food) but now I think I'm wrong , Boilerplates are those codes which repeated in many places in the whole code.

Can anyone make this thing clear to me in flutter (in simple language)?

Shruti Ramnandan Sharma
  • 4,027
  • 13
  • 44
  • 76

1 Answers1

4

boilerplate means a piece of code that can be used over and over again in a specifc part of an app, or to do the same operation, maybe with slight modifications. For example all Winforms apps (windows desktop app) start like this

namespace WinFormsApp3 {
    internal static class Program {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            // To customize application configuration such as set high DPI settings or default font,
            // see https://aka.ms/applicationconfiguration.
            ApplicationConfiguration.Initialize();
            Application.Run(new Form1());
        }
    }
}

in fact this is so 'boilerplate' that it is generated automatically by the IDE. Just a few names get changed.

Most devs dont even look at it because they just recognize it as 'biolerplate'

I dont know flutter but I bet there are similar pieces of code that all flutter apps have

I just read about how to create a flutter app. The automatically generated lib/main.dart is classic boilerplate

another example. THis is bootstraps 'getting started ' page

https://getbootstrap.com/docs/5.1/getting-started/introduction/

Look at the bit headed 'starter template', again this is classic boilerplate. I know I just copy pasted it for my first few apps

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
    -->
  </body>
</html>
pm100
  • 48,078
  • 23
  • 82
  • 145