Created with <3 with dartpad.dev.
Last active
September 22, 2022 13:41
-
-
Save singlesoup/f37153e32755c5bf78c3d253dbe6515c to your computer and use it in GitHub Desktop.
Abstract Classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:developer' as devtools show log; | |
extension Log on Object { | |
void log() => devtools.log(toString()); | |
} | |
enum Type { cat, dog } | |
abstract class CanRun { | |
final Type type; | |
const CanRun({required this.type}); | |
@mustCallSuper | |
void run() { | |
"CanRun func is called".log(); | |
} | |
} | |
class Dog extends CanRun { | |
const Dog() : super(type: Type.dog); | |
} | |
class Cat extends CanRun { | |
const Cat() : super(type: Type.cat); | |
@override | |
run() { | |
super.run(); | |
"Cat func is called".log(); | |
} | |
} | |
void testIt() { | |
const cat = Cat(); | |
cat.type.log(); | |
const dog = Dog(); | |
dog.type.log(); | |
} | |
abstract class CanSee{ | |
void see(){ | |
"Sight...".log(); | |
} | |
} | |
abstract class CanHunt{ | |
void hunt(){ | |
"Hunting...".log(); | |
} | |
} | |
class BigCat with CanSee, CanHunt{ | |
} | |
void observe(){ | |
final bigCat = BigCat(); | |
// bigCat.see(); | |
// bigCat.hunt(); | |
bigCat..see()..hunt(); | |
} | |
void main() { | |
'Hello'.log(); | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
testIt(); | |
observe(); | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: Colors.amberAccent, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Text( | |
'Hello, World!', | |
style: | |
Theme.of(context).textTheme.headline5!.copyWith(color: Colors.black), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment