Skip to content

fontVariations property is not animatable within AnimatedDefaultTextStyle #105120

Closed

Description

@epentesi

Steps to Reproduce

  1. Switch Flutter framework to master channel (3.1.0-0.0.pre.1037, at the moment)
  2. Add the variable font Roboto Flex TTF file to your project (download page: https://fonts.google.com/specimen/Roboto+Flex)
/
│
└── fonts/
    └── RobotoFlex-VariableFont_GRAD,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght.ttf
  1. Update pubspec.yaml file
  fonts:
    - family: 'Roboto Flex'
      fonts:
        - asset: 'fonts/RobotoFlex-VariableFont_GRAD,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght.ttf'
  1. Execute flutter run on the code sample
  2. Click on Color or Font size button and see how the changes for the sample text above (þΩ) of those properties take place over a period of time (2 seconds)
  3. Click now on Weight (wght) or Width (wdth) or Slant (slnt) (some of font axes of Roboto Flex) and see how the changes for the text (þΩ) take place immediately

Expected results:
When a FontVariation value changes for the fontVariations property, that change should take place over a period of time.

Actual results:
The fontVariations changes take place immediately.

Code sample
import 'dart:math';
import 'dart:ui';

import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Animated Default Text Style'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _console = '—';

  double getRandomValue(List<double> range) {
    double value = range[0] + Random().nextDouble() * (range[1] - range[0]);
    return value;
  }

  final List<Color> _textColorList = [
    Colors.grey,
    Colors.red,
    Colors.green,
    Colors.blue,
    Colors.yellow,
    Colors.purple,
    Colors.indigo,
    Colors.orange,
  ];
  Color _textColor = Colors.black;
  final List<double> _fontSizeRange = [36.0, 190];
  double _fontSize = 190.0;
  final List<double> _weightRange = [100.0, 1000];
  double _weight = 1000.0;
  final List<double> _widthRange = [25.0, 151];
  double _width = 151.0;
  final List<double> _slantRange = [-10.0, 0.0];
  double _slant = 0.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      backgroundColor: Colors.grey.shade50,
      body: SafeArea(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const SizedBox(
              height: 32.0,
            ),
            Text(
              _console,
              style: const TextStyle(
                fontFamily: 'Menlo',
                fontFamilyFallback: ['monospace'],
              ),
            ),
            Expanded(
              child: Center(
                child: AnimatedDefaultTextStyle(
                  duration: const Duration(seconds: 2),
                  curve: Curves.elasticOut,
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    fontFamily: 'Roboto Flex',
                    color: _textColor,
                    fontSize: _fontSize,
                    fontVariations: [
                      FontVariation('wght', _weight),
                      FontVariation('wdth', _width),
                      FontVariation('slnt', _slant),
                    ],
                  ),
                  child: const Text(
                    'þΩ',
                  ),
                ),
              ),
            ),
            const SizedBox(
              height: 64.0,
            ),
            const Divider(
              thickness: 4,
            ),
            const Text('Animatable properties'),
            Wrap(
              spacing: 16.0,
              alignment: WrapAlignment.center,
              children: [
                ElevatedButton(
                    onPressed: () {
                      setState(() {
                        _textColor = _textColorList[
                            Random().nextInt(_textColorList.length)];
                        _console =
                            'Color: ${_textColor.value.toRadixString(16).toUpperCase()}';
                      });
                    },
                    child: const Text('Color')),
                ElevatedButton(
                    onPressed: () {
                      setState(() {
                        _fontSize = getRandomValue(_fontSizeRange);
                        _console = 'Font size: ${_fontSize.toStringAsFixed(1)}';
                      });
                    },
                    child: const Text('Font size')),
              ],
            ),
            const Divider(
              thickness: 4,
            ),
            const Text('Font variations (non animatable properties)'),
            Wrap(
              spacing: 16.0,
              alignment: WrapAlignment.center,
              children: [
                ElevatedButton(
                    onPressed: () {
                      setState(() {
                        _weight = getRandomValue(_weightRange);
                        _console = 'Weight: ${_weight.toStringAsFixed(1)}';
                      });
                    },
                    child: const Text('Weight (wght)')),
                ElevatedButton(
                    onPressed: () {
                      setState(() {
                        _width = getRandomValue(_widthRange);
                        _console = 'Width: ${_width.toStringAsFixed(1)}';
                      });
                    },
                    child: const Text('Width (wdth)')),
                ElevatedButton(
                    onPressed: () {
                      setState(() {
                        _slant = getRandomValue(_slantRange);
                        _console = 'Slant: ${_slant.toStringAsFixed(1)}';
                      });
                    },
                    child: const Text('Slant (slnt)')),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
Demo video
NonAnimatableFontVariations.mp4

Activity

  1. danagbemava-nc commented on Jun 1, 2022

    @danagbemava-nc
    Member

    Issue is reproducible on master & beta using the code sample provided above.

    It is more noticeable if slow animations is turned on in the devtools. You'll see the text animate in slo-mo when the color and font size change, but the same effect isn't seen when the weight/width/slant is changed.

    Labeling for further investigation.

    Font has been attached below for easy access

    video
    Screen.Recording.2022-06-01.at.13.18.08.mov
    flutter doctor -v
    [✓] Flutter (Channel beta, 3.1.0, on macOS 12.3.1 21E258 darwin-arm, locale en-GB)
        • Flutter version 3.1.0 at /Users/nexus/dev/sdks/flutter_beta
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision bcea432bce (6 days ago), 2022-05-26 09:05:34 -0700
        • Engine revision 44e5b38ee8
        • Dart version 2.18.0 (build 2.18.0-44.1.beta)
        • DevTools version 2.12.2
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-32, 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.3.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.67.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.40.0
    
    [✓] Connected device (3 available)
        • iPhone 13 (mobile) • DBB48503-41CE-4969-9043-3261726E438A • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
        • macOS (desktop)    • macos                                • darwin-arm64   • macOS 12.3.1 21E258 darwin-arm
        • Chrome (web)       • chrome                               • web-javascript • Google Chrome 102.0.5005.61
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [✓] Flutter (Channel master, 3.1.0-0.0.pre.1035, on macOS 12.3.1 21E258 darwin-arm, locale en-GB)
        • Flutter version 3.1.0-0.0.pre.1035 at /Users/nexus/dev/sdks/flutters
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 3d62732d60 (9 hours ago), 2022-06-01 00:14:14 -0400
        • Engine revision 0d1057ef7b
        • Dart version 2.18.0 (build 2.18.0-157.0.dev)
        • DevTools version 2.13.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-32, 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.3.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.67.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.40.0
    
    [✓] Connected device (3 available)
        • iPhone 13 (mobile) • DBB48503-41CE-4969-9043-3261726E438A • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
        • macOS (desktop)    • macos                                • darwin-arm64   • macOS 12.3.1 21E258 darwin-arm
        • Chrome (web)       • chrome                               • web-javascript • Google Chrome 102.0.5005.61
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    

    font

  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Jun 1, 2022
  3. added
    P3Issues that are less important to the Flutter project
    on Jun 1, 2022
  4. self-assigned this
    on Aug 23, 2023
  5. github-actions commented on Dec 25, 2023

    @github-actions

    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.

  6. locked as resolved and limited conversation to collaborators on Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projecta: animationAnimation APIsfound in release: 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions