Call Function From Same Class On Click Button
Complete Code For Call Function From Same Class On Click Button 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 sampleFunction_1() { print('Function Called'); } void sampleFunction_2(String holder) { print(holder); } void sampleFunction_3(double value){ print(value); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.red[900], title: Text('Call Function From Same Class'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Container( child: RaisedButton( onPressed: () => sampleFunction_1(), child: Text(' Function Without Argument '), textColor: Colors.white, color: Colors.red[900], ) ), Container( child: RaisedButton( onPressed: () => sampleFunction_2('Hello Word'), child: Text(' Function With String Argument '), textColor: Colors.white, color: Colors.red[400], ) ), Container( child: RaisedButton( onPressed: () => sampleFunction_3(145.123), child: Text(' Function With Double Float Argument '), textColor: Colors.white, color: Colors.red[900], ) ) ]) ) ); } }