How To Create Call Fat Arrow One Line Function Using Flutter

admin_img Posted By Bajarangi soft , Posted On 03-11-2020

we would use the normal function syntax where every code we want to execute in function in function body. But it would make the function bigger in size so to make functions smaller in size and easier to update we would use Fat Arrow function declaration method. Using the Fat Arrow we can declare the function in one line without declaring the function body.

How To Create Call Fat Arrow One Line Function Using Flutter

Fat Arrow One Line Function
Complete Code For Fat Arrow One Line Function In Flutter
main.dart

import 'package:flutter/material.dart';
void main(){
  runApp(MyApp());
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  void shortFunction() => print('Fat Arrow One Line Function Called');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.blue[700],
        title: Text('Fat Arrow One Line Function'),
      ),
            body: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                          child: RaisedButton(
                            onPressed: () => shortFunction(),
                            child: Text('Call One Line Short Function'),
                            textColor: Colors.white,
                            color: Colors.blue[700],
                          )
                      ),
                    ])
            )
    );
  }
}

Related Post