Chrome Extension

Simple stateless widget in Flutter

import 'package:flutter/material.dart'

class WidgetName extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'App title',
      home: Container(
        child: Text('Hello World'),
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

This is a simple code snippet for creating a Stateless widget in Flutter. As you know that we can create two types of widgets in Flutter - Stateless Widgets and Stateful widgets.

To create a stateless widget in Flutter, first, we import package 'package:flutter/material.dart' it means you can use inbuilt flutter widgets in your app. Then we create a class with class name 'WidgetName'. You can change it as per your requirement. Now we extend StatelessWidget class in our class sp that you can return your layout as a widget.

Now we override build function by using the @override keyword above it and return the widget layout. We are using MaterialApp as a parent component that has 'title' and 'home' params where we can structure the widget. 

Was this helpful?
Join Devsheet Ask a Question