Skip to content

Commit

Permalink
Add Flutter 3.0 support
Browse files Browse the repository at this point in the history
This specific implementation allows for backward compatibility as mentioned here: https://docs.flutter.dev/development/tools/sdk/release-notes/release-notes-3.0.0#your-code.

Closes #87.
  • Loading branch information
CharlesMangwa committed May 27, 2022
1 parent f99493c commit 1aa6322
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/papercups_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,19 @@ class _PaperCupsWidgetState extends State<PaperCupsWidget> {
_conversationChannel = c;
}

/// This allows a value of type T or T?
/// to be treated as a value of type T?.
///
/// We use this so that APIs that have become
/// non-nullable can still be used with `!` and `?`
/// to support older versions of the API as well.
T? _ambiguate<T>(T? value) => value;

void rebuild(void Function() fn, {bool stateMsg = false, animate = false}) {
_sending = stateMsg;
if (mounted) setState(fn);
if (animate &&
mounted &&
_conversation.messages.isNotEmpty &&
WidgetsBinding.instance != null &&
_controller.hasClients) {
WidgetsBinding.instance!.addPostFrameCallback((_) {
if (animate && mounted && _conversation.messages.isNotEmpty && _controller.hasClients) {
_ambiguate(WidgetsBinding.instance)?.addPostFrameCallback((_) {
_controller.animateTo(
_controller.position.maxScrollExtent,
curve: Curves.easeIn,
Expand Down

0 comments on commit 1aa6322

Please sign in to comment.