| // 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 'package:flutter/material.dart'; |
| |
| /// Flutter code sample for [LinearProgressIndicator]. |
| |
| void main() => runApp(const ProgressIndicatorApp()); |
| |
| class ProgressIndicatorApp extends StatelessWidget { |
| const ProgressIndicatorApp({super.key}); |
| |
| @override |
| Widget build(BuildContext context) { |
| return const MaterialApp( |
| home: ProgressIndicatorExample(), |
| ); |
| } |
| } |
| |
| class ProgressIndicatorExample extends StatefulWidget { |
| const ProgressIndicatorExample({super.key}); |
| |
| @override |
| State<ProgressIndicatorExample> createState() => _ProgressIndicatorExampleState(); |
| } |
| |
| class _ProgressIndicatorExampleState extends State<ProgressIndicatorExample> with TickerProviderStateMixin { |
| late AnimationController controller; |
| |
| @override |
| void initState() { |
| controller = AnimationController( |
| /// [AnimationController]s can be created with `vsync: this` because of |
| /// [TickerProviderStateMixin]. |
| vsync: this, |
| duration: const Duration(seconds: 5), |
| )..addListener(() { |
| setState(() {}); |
| }); |
| controller.repeat(reverse: true); |
| super.initState(); |
| } |
| |
| @override |
| void dispose() { |
| controller.dispose(); |
| super.dispose(); |
| } |
| |
| @override |
| Widget build(BuildContext context) { |
| return Scaffold( |
| body: Padding( |
| padding: const EdgeInsets.all(20.0), |
| child: Column( |
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
| children: <Widget>[ |
| const Text( |
| 'Linear progress indicator with a fixed color', |
| style: TextStyle(fontSize: 20), |
| ), |
| LinearProgressIndicator( |
| value: controller.value, |
| semanticsLabel: 'Linear progress indicator', |
| ), |
| ], |
| ), |
| ), |
| ); |
| } |
| } |