Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextStyle.lerp throw assert error when typography is changed from/to Typography.material2018 #108675

Closed
SuperPenguin opened this issue Jul 30, 2022 · 2 comments
Labels
r: duplicate Issue is closed as a duplicate of an existing issue

Comments

@SuperPenguin
Copy link
Contributor

Steps to Reproduce

  1. Run example code
  2. Tap Material 3, then tap Material 1
  3. Tap Material 2, then tap Material 1/3, then tap again to Material 2

Expected results: No error

Actual results: TextStyle.lerp throw assertion error

Code sample
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const App());
}

enum AppMode {
  material1(label: 'Material 1'),
  material2(label: 'Material 2'),
  material3(label: 'Material 3');

  const AppMode({required this.label});

  final String label;
}

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  State<App> createState() => AppState();

  static AppState stateOf(BuildContext context) {
    return context.findAncestorStateOfType<AppState>()!;
  }
}

class AppState extends State<App> {
  AppMode _appMode = AppMode.values.first;

  void setAppMode(AppMode appMode) {
    if (_appMode != appMode) {
      setState(() {
        _appMode = appMode;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        brightness: Brightness.light,
        useMaterial3: _appMode == AppMode.material3,
        typography: _appMode == AppMode.material3
            ? Typography.material2021(platform: defaultTargetPlatform)
            : _appMode == AppMode.material2
                ? Typography.material2018(platform: defaultTargetPlatform)
                : Typography.material2014(platform: defaultTargetPlatform),
      ),
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                for (final m in AppMode.values)
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 4.0),
                    child: ElevatedButton(
                      onPressed: () => App.stateOf(context).setAppMode(m),
                      child: Text(m.label),
                    ),
                  ),
              ],
            ),
            const Expanded(
              child: TextThemeShowcase(),
            ),
          ],
        ),
      ),
    );
  }
}

class TextThemeShowcase extends StatelessWidget {
  const TextThemeShowcase({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final textTheme = Theme.of(context).textTheme;
    final infos = TextStyleInfo.listFromTextTheme(textTheme);

    return ListView.builder(
      itemCount: infos.length,
      itemBuilder: (context, index) {
        final textInfo = infos[index];

        return Card(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Text(textInfo.name, style: textInfo.style),
                Text('FontSize: ${textInfo.style?.fontSize}'),
                Text('FontWeight: ${textInfo.style?.fontWeight}'),
              ],
            ),
          ),
        );
      },
    );
  }
}

@immutable
class TextStyleInfo {
  const TextStyleInfo({
    required this.name,
    required this.style,
  });

  final String name;
  final TextStyle? style;

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other.runtimeType == runtimeType &&
        other is TextStyleInfo &&
        other.name == name &&
        other.style == style;
  }

  @override
  int get hashCode => Object.hash(runtimeType, name, style);

  static List<TextStyleInfo> listFromTextTheme(TextTheme textTheme) {
    return [
      // Display
      TextStyleInfo(name: 'Display Large', style: textTheme.displayLarge),
      TextStyleInfo(name: 'Display Medium', style: textTheme.displayMedium),
      TextStyleInfo(name: 'Display Small', style: textTheme.displaySmall),
      // Headline
      TextStyleInfo(name: 'Headline Large', style: textTheme.headlineLarge),
      TextStyleInfo(name: 'Headline Medium', style: textTheme.headlineMedium),
      TextStyleInfo(name: 'Headline Small', style: textTheme.headlineSmall),
      // Title
      TextStyleInfo(name: 'Title Large', style: textTheme.titleLarge),
      TextStyleInfo(name: 'Title Medium', style: textTheme.titleMedium),
      TextStyleInfo(name: 'Title Small', style: textTheme.titleSmall),
      // Label
      TextStyleInfo(name: 'Label Large', style: textTheme.labelLarge),
      TextStyleInfo(name: 'Label Medium', style: textTheme.labelMedium),
      TextStyleInfo(name: 'Label Small', style: textTheme.labelSmall),
      // Body
      TextStyleInfo(name: 'Body Large', style: textTheme.bodyLarge),
      TextStyleInfo(name: 'Body Medium', style: textTheme.bodyMedium),
      TextStyleInfo(name: 'Body Small', style: textTheme.bodySmall),
    ];
  }
}
Logs
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building AnimatedTheme(duration: 200ms, dirty, state: _AnimatedThemeState#dd243(ticker active, ThemeDataTween(ThemeData#1ae13 → ThemeData#87eb2))):
'package:flutter/src/painting/text_style.dart': Failed assertion: line 1047 pos 12: 'a == null || b == null || a.inherit == b.inherit': is not true.
package:flutter/…/painting/text_style.dart:1047
2

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was
MaterialApp
lib/main.dart:42
When the exception was thrown, this was the stack
#2      TextStyle.lerp
package:flutter/…/painting/text_style.dart:1047
#3      TextTheme.lerp
package:flutter/…/material/text_theme.dart:615
#4      Typography.lerp
package:flutter/…/material/typography.dart:317
#5      ThemeData.lerp
package:flutter/…/material/theme_data.dart:2068
#6      ThemeDataTween.lerp
package:flutter/…/material/theme.dart:176
#7      Tween.transform
package:flutter/…/animation/tween.dart:327
#8      Animatable.evaluate
package:flutter/…/animation/tween.dart:53
#9      _AnimatedThemeState.build
package:flutter/…/material/theme.dart:232
#10     StatefulElement.build
package:flutter/…/widgets/framework.dart:4919
#11     ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4806
#12     StatefulElement.performRebuild
package:flutter/…/widgets/framework.dart:4977
#13     Element.rebuild
package:flutter/…/widgets/framework.dart:4529
#14     BuildOwner.buildScope
package:flutter/…/widgets/framework.dart:2659
#15     WidgetsBinding.drawFrame
package:flutter/…/widgets/binding.dart:891
#16     RendererBinding._handlePersistentFrameCallback
package:flutter/…/rendering/binding.dart:370
#17     SchedulerBinding._invokeFrameCallback
package:flutter/…/scheduler/binding.dart:1146
#18     SchedulerBinding.handleDrawFrame
package:flutter/…/scheduler/binding.dart:1083
#19     SchedulerBinding._handleDrawFrame
package:flutter/…/scheduler/binding.dart:997
#23     _invoke (dart:ui/hooks.dart:151:10)
#24     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#25     _drawFrame (dart:ui/hooks.dart:115:31)
(elided 5 frames from class _AssertionError and dart:async)
════════════════════════════════════════════════════════════════════════════════
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-arm, locale en-ID)
    • Flutter version 3.0.5 at /Users/s21/Documents/GitHub/flutter/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (2 weeks ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/s21/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.69.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.44.0

[✓] Connected device (4 available)
    • SM G991B (mobile)        • RRCR2003SSA               • android-arm64  • Android 12 (API 31)
    • Andree’s iPhone (mobile) • 00008030-000314393443802E • ios            • iOS 15.6 19G71
    • macOS (desktop)          • macos                     • darwin-arm64   • macOS 12.4 21F79 darwin-arm
    • Chrome (web)             • chrome                    • web-javascript • Google Chrome 103.0.5060.134
    ! Error: Andree’s iPhone is busy: Fetching debug symbols for Andree’s iPhone. Xcode will continue when Andree’s iPhone is finished. (code -10)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Aug 1, 2022
@danagbemava-nc
Copy link
Member

Closing this as a duplicate of #103864.

Kindly follow up in the linked issue for updates.

Please upvote the linked issue as well.

Thank you

@danagbemava-nc danagbemava-nc closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2022
@danagbemava-nc danagbemava-nc added r: duplicate Issue is closed as a duplicate of an existing issue and removed in triage Presently being triaged by the triage team labels Aug 1, 2022
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: duplicate Issue is closed as a duplicate of an existing issue
Projects
None yet
Development

No branches or pull requests

2 participants