Interface In Dart :
- Class implements interface then it must override every method and instance variable of interface.
- Dart does not have a syntax for declaring interfaces. The class declaration is themselves interface in a dart.

class Framework{ void kotlin() { print("kotiln is good lanaguge"); } void flutter() { print("Flutter next generation lanaguge"); } } class Android implements Framework { @override void kotlin() { print("call kotlin"); } @override void flutter() { print("call flutter"); } } main() { Framework framework = new Framework(); Android android = new Android(); framework.kotlin(); framework.flutter(); android.kotlin(); android.flutter(); }
output :
kotiln is good lanaguge
Flutter next generation lanaguge
call kotlin
call flutter
Real time example interface :
class ButtonClickListener { void onButtonClick() { print("Default Button Clicked !!"); } } class Login implements ButtonClickListener { // implement all the methods of ButtonClickListener onButtonClick() { print("Login Button Clicked !!"); } } class Signup implements ButtonClickListener { // implement all the methods of ButtonClickListener onButtonClick() { print("Signup Button Clicked !!"); } } void main() { // you can create an object of a class which act as implicit interface ButtonClickListener listener = new ButtonClickListener(); listener.onButtonClick(); Login login = new Login(); login.onButtonClick(); Signup signUp = new Signup(); signUp.onButtonClick(); }
Multiple Interface :
Dart does not support multiple inheritance but dart can implement multiple interfaces.
Syntax :
class class_name implements interface1, interface2, interface3
class Person { String name; void showName() { print("My name is $name"); } void walk() { print("Persxon can walk"); } void talk() { print("Person can talk"); } } class Kamlesh { String profession; void showProfession() { print("from class kamlesh my profession is $profession"); } } class Jay implements Person, Kamlesh { @override String profession; @override void showProfession() { print("from class Jay my Profession is $profession"); } @override String name; @override void showName() { print("From class Jay my name is $name"); } @override void walk() { print("Jay can walk"); } @override void talk() { print("Jay can talk"); } } main() { Person person = new Person(); Jay jay.name = "JAY"; jay = new Jay(); Kamlesh kamlesh = new Kamlesh(); person.walk(); person.talk(); person.name = "Person"; person.showName(); print(""); jay.walk(); jay.talk(); jay.profession = "Chemical Engineer"; kamlesh.showProfession(); jay.showName(); print(""); kamlesh.profession = "Software Development"; kamlesh.showProfession(); }
Output :
Person can walk
Person can talk
My name is Person
Jay can walk
Jay can talk
from class kamlesh my profession is null
From class Jay my name is JAY
from class kamlesh my profession is Software Development
The flutter tutorial is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application
For more information about Flutter. visit www.fluttertutorial.in