
Related to [Update both `ProgressIndicator` for Material 3 redesign](https://github.com/flutter/flutter/issues/141340) ### 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 StatefulWidget { const MyApp({super.key}); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { bool isRTL = false; @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Directionality( textDirection: isRTL ? TextDirection.rtl : TextDirection.ltr, child: Center( child: Column( spacing: 2.0, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ const Text('Default LinearProgressIndicator'), const Padding( padding: EdgeInsets.all(16.0), child: LinearProgressIndicator( value: 0.45, ), ), const Text('Default indefinite LinearProgressIndicator'), const Padding( padding: EdgeInsets.all(16.0), child: LinearProgressIndicator(), ), const Text('Updated height and border radius'), Padding( padding: const EdgeInsets.all(16.0), child: LinearProgressIndicator( value: 0.25, minHeight: 16.0, borderRadius: BorderRadius.circular(16.0), ), ), const Text('Updated stop indicator color and radius'), Padding( padding: const EdgeInsets.all(16.0), child: LinearProgressIndicator( value: 0.74, minHeight: 16.0, borderRadius: BorderRadius.circular(16.0), stopIndicatorColor: Theme.of(context).colorScheme.error, stopIndicatorRadius: 32.0, ), ), const Text('Track gap and stop indicator radius set to 0'), Padding( padding: const EdgeInsets.all(16.0), child: LinearProgressIndicator( value: 0.50, minHeight: 16.0, borderRadius: BorderRadius.circular(16.0), trackGap: 0, stopIndicatorRadius: 0, ), ), ], ), ), ), floatingActionButton: FloatingActionButton.extended( onPressed: () { setState(() { isRTL = !isRTL; }); }, label: const Text('Toggle Direction'), ), ), ); } } ``` </details> ### Preview <img width="824" alt="Screenshot 2024-09-09 at 13 53 10" src="https://github.com/user-attachments/assets/d12e56a5-f196-4011-8266-c7ab96be96b2">
56 lines
1.8 KiB
Dart
56 lines
1.8 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'template.dart';
|
|
|
|
class ProgressIndicatorTemplate extends TokenTemplate {
|
|
const ProgressIndicatorTemplate(super.blockName, super.fileName, super.tokens, {
|
|
super.colorSchemePrefix = '_colors.',
|
|
});
|
|
|
|
@override
|
|
String generate() => '''
|
|
class _Circular${blockName}DefaultsM3 extends ProgressIndicatorThemeData {
|
|
_Circular${blockName}DefaultsM3(this.context);
|
|
|
|
final BuildContext context;
|
|
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
|
|
|
@override
|
|
Color get color => ${componentColor('md.comp.progress-indicator.active-indicator')};
|
|
|
|
@override
|
|
Color get circularTrackColor => ${componentColor('md.comp.progress-indicator.track')};
|
|
}
|
|
|
|
class _Linear${blockName}DefaultsM3 extends ProgressIndicatorThemeData {
|
|
_Linear${blockName}DefaultsM3(this.context);
|
|
|
|
final BuildContext context;
|
|
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
|
|
|
@override
|
|
Color get color => ${componentColor('md.comp.progress-indicator.active-indicator')};
|
|
|
|
@override
|
|
Color get linearTrackColor => ${componentColor('md.comp.progress-indicator.track')};
|
|
|
|
@override
|
|
double get linearMinHeight => ${getToken('md.comp.progress-indicator.track.thickness')};
|
|
|
|
@override
|
|
BorderRadius get borderRadius => BorderRadius.circular(${getToken('md.comp.progress-indicator.track.thickness')} / 2);
|
|
|
|
@override
|
|
Color get stopIndicatorColor => ${componentColor('md.comp.progress-indicator.stop-indicator')};
|
|
|
|
@override
|
|
double? get stopIndicatorRadius => ${getToken('md.comp.progress-indicator.stop-indicator.size')} / 2;
|
|
|
|
@override
|
|
double? get trackGap => ${getToken('md.comp.progress-indicator.active-indicator-track-space')};
|
|
}
|
|
''';
|
|
}
|