Created with <3 with dartpad.dev.
Created
August 20, 2023 20:19
-
-
Save mernen/abd19bc8f0bf3db07116b1b037774cd3 to your computer and use it in GitHub Desktop.
defaultTextStyleOf null dereference
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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
body: Center( | |
child: CustomButton( | |
onPressed: () {}, | |
child: const Text('Custom button'), | |
), | |
), | |
), | |
); | |
} | |
} | |
class CustomButton extends TextButton { | |
const CustomButton({ | |
super.key, | |
required super.onPressed, | |
required super.child, | |
}); | |
@override | |
ButtonStyle defaultStyleOf(BuildContext context) { | |
return TextButton.styleFrom( | |
foregroundColor: Colors.teal, | |
// ...other custom styles here | |
// The following lines are now required to prevent null dereferences: | |
// enabledMouseCursor: SystemMouseCursors.click, | |
// disabledMouseCursor: SystemMouseCursors.basic, | |
).merge(super.defaultStyleOf(context)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment