BirjuVachhani / adaptive_theme

Easiest way to add support for light and dark theme in your flutter app.
https://pub.dev/packages/adaptive_theme
Apache License 2.0
464 stars 37 forks source link

CupertinoApp - Dynamic Theme Change Issue #58

Closed kamaravichow closed 7 months ago

kamaravichow commented 7 months ago

Describe the bug Issue occurs when you try to change theme in a CupertinoApp with No Material app

To Reproduce Steps to reproduce the behavior: Use CupertinoApp and try to change theme dynamically

Expected behavior Change Theme , but no

Additional context

E/flutter (24247): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter (24247): #0      AdaptiveTheme.of (package:adaptive_theme/src/adaptive_theme.dart:72:45)
E/flutter (24247): #1      _AppScreenState.afterFirstLayout (package:app/app_screen.dart:86:19)
E/flutter (24247): #2      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:846:45)
E/flutter (24247): #3      Future._propagateToListeners (dart:async/future_impl.dart:875:13)
E/flutter (24247): #4      Future._completeWithValue (dart:async/future_impl.dart:647:5)
E/flutter (24247): #5      Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:721:7)
E/flutter (24247): #6      _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (24247): #7      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (24247): 

Basically,

        AdaptiveTheme.of(context).setLight();

doesn't work with CupertinoApp

BirjuVachhani commented 7 months ago

You need to use CupertinoAdaptiveTheme.of(context).setLight();