Skip to content

Instantly share code, notes, and snippets.

@huynguyennovem
Created March 8, 2022 13:41
Show Gist options
  • Save huynguyennovem/e4e8ac98ca0616777737e4ab53c7dbf4 to your computer and use it in GitHub Desktop.
Save huynguyennovem/e4e8ac98ca0616777737e4ab53c7dbf4 to your computer and use it in GitHub Desktop.
AnimatedTheme throws exceptions when switching
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool dark = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Material(
child: AnimatedTheme(
data: dark ? ThemeData.dark() : Theme.of(context),
child: Center(
child: Container(
color: dark ? Colors.black : Colors.white,
child: FlatButton(
onPressed: () {
setState(() { dark = !dark;});
},
child: Text('TEST'),
),
),
),
),
),
);
}
}
@huynguyennovem
Copy link
Author

  • Issue: flutter/flutter#43358
  • Flutter version: 2.10.3
  • Tested device: Mac OS Big Sur 11.6 M1
    Chrome 98.0.4758.109 (Official Build) (arm64)
  • Replicable: Yes

Exception log:

======== Exception caught by widgets library =======================================================
The following assertion was thrown building AnimatedTheme(duration: 200ms, dirty, state: _AnimatedThemeState#81d9c(ticker active, ThemeDataTween(ThemeData#76c73 → ThemeData#9b912))):
Assertion failed: file:///Users/eriknguyen/Documents/flutter/packages/flutter/lib/src/painting/text_style.dart:1048:12
a == null || b == null || a.inherit == b.inherit
is not true

The relevant error-causing widget was: 
  AnimatedTheme AnimatedTheme:file:///Users/eriknguyen/Desktop/CodeMagic/99715/lib/main_43358.dart:23:16
When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed
packages/flutter/src/painting/text_style.dart 1048:52                         lerp
packages/flutter/src/material/text_theme.dart 615:31                          lerp
packages/flutter/src/material/theme_data.dart 1908:28                         lerp
packages/flutter/src/material/theme.dart 174:41                               lerp
packages/flutter/src/animation/tween.dart 327:12                              transform
packages/flutter/src/animation/tween.dart 53:46                               evaluate
packages/flutter/src/material/theme.dart 230:13                               build
packages/flutter/src/widgets/framework.dart 4870:27                           build
packages/flutter/src/widgets/framework.dart 4754:15                           performRebuild
packages/flutter/src/widgets/framework.dart 4928:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4477:5                            rebuild
packages/flutter/src/widgets/framework.dart 2659:18                           buildScope
packages/flutter/src/widgets/binding.dart 882:9                               drawFrame
packages/flutter/src/rendering/binding.dart 363:5                             [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1144:15                           [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1081:9                            handleDrawFrame
packages/flutter/src/scheduler/binding.dart 995:5                             [_handleDrawFrame]
lib/_engine/engine/platform_dispatcher.dart 1011:13                           invoke
lib/_engine/engine/platform_dispatcher.dart 159:5                             invokeOnDrawFrame
lib/_engine/engine/initialization.dart 128:45                                 <fn>
====================================================================================================
Screen.Recording.2022-03-08.at.8.38.48.PM.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment