Abstract Class Can Not Be Instantiated Using Flutter Android

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

Abstract classes works like a base of Sub class like skeleton in boys which holds all the function names before we start making them. This would make development easier for developer.

Abstract Class Can Not Be Instantiated Using Flutter Android

Abstract Class Can Not Be Instantiated
Complete Code For Abstract Class Can Not Be Instantiated In Flutter
main.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

abstract class Message{
  void Hello();
  void By();
}
class Second extends Message {
  void Hello(){
    print('Hello Guys Welcome To BajarangiSoft...');
  }
  void By(){
    print('By Guys...');
  }

}

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 {
  final second = new Second();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.pink[600],
        title: Text('Abstract Class'),
      ),
            body: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[

                      Container(
                          child: RaisedButton(
                            onPressed: () => second.Hello(),
                            child: Text('Call Abstract Class Hello Function',
                              textAlign: TextAlign.center,),
                            textColor: Colors.white,
                            color: Colors.pink,
                          )
                      ),

                      Container(
                          child: RaisedButton(
                            onPressed: () => second.By(),
                            child: Text('Call Abstract Class By Function',
                                textAlign: TextAlign.center),
                            textColor: Colors.white,
                            color: Colors.pink[600],
                          )
                      ),
                    ])
            )
    );
  }
}

Related Post