flutter/dev/tools/gen_defaults
Taha Tesser 0bcd228e67
Update TabBar and TabBar.secondary to use indicator height/color M3 tokens (#145753)
fixes [Secondary `TabBar` indicator height token is missing ](https://github.com/flutter/flutter/issues/124965)

### Code sample

<details>
<summary>expand to view the code sample</summary> 

```dart
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            title: const Text('Sample'),
            bottom: const TabBar.secondary(
              tabs: <Widget>[
                Tab(icon: Icon(Icons.directions_car)),
                Tab(icon: Icon(Icons.directions_transit)),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: () {},
            child: const Icon(Icons.add),
          ),
        ),
      ),
    );
  }
}
```

</details>
2024-03-28 17:56:09 +00:00
..
bin Implementing null-aware operators throughout the repository (#143804) 2024-02-23 19:02:22 +00:00
data Reland "Reland - Introduce tone-based surfaces and accent color add-ons - Part 2" (#144273) 2024-02-28 13:55:50 -08:00
generated Update TabBar and TabBar.secondary to use indicator height/color M3 tokens (#145753) 2024-03-28 17:56:09 +00:00
lib Update TabBar and TabBar.secondary to use indicator height/color M3 tokens (#145753) 2024-03-28 17:56:09 +00:00
test Fix gen_defaults test randomness (#142743) 2024-02-01 21:22:51 +00:00
dart_test.yaml Really disable shuffling for gen_defaults tests (#142721) 2024-02-01 10:09:07 -08:00
pubspec.yaml Roll pub packages (#145476) 2024-03-21 00:09:24 +00:00
README.md Improve defaults generation with logging, stats, and token validation (#128244) 2023-06-09 11:28:18 +00:00
test.json Improve defaults generation with logging, stats, and token validation (#128244) 2023-06-09 11:28:18 +00:00

Token Defaults Generator

Script that generates component theme data defaults based on token data.

Usage

Run this program from the root of the git repository:

dart dev/tools/gen_defaults/bin/gen_defaults.dart [-v]

This updates generated/used_tokens.csv and the various component theme files.

Templates

There is a template file for every component that needs defaults from the token database. These templates are implemented as subclasses of TokenTemplate. This base class provides some utilities and a structure for adding a new block of generated code to the bottom of a given file.

Templates need to override the generate method to provide the generated code block as a string.

See lib/fab_template.dart for an example that generates defaults for the Floating Action Button.

Tokens

Tokens are stored in JSON files in data/, and are sourced from an internal Google database.

template.dart should provide nearly all useful token resolvers (e.g. color, shape, etc.). For special cases in which one shouldn't be defined, use getToken to get the raw token value. The script, through the various revolvers and getToken, validates tokens, keeps track of which tokens are used, and generates generated/used_tokens.csv.