85 lines
2.2 KiB
Dart
85 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class ProgressWidget extends StatefulWidget {
|
|
const ProgressWidget({super.key});
|
|
|
|
@override
|
|
State<ProgressWidget> createState() =>
|
|
_ProgressWidget();
|
|
}
|
|
|
|
class _ProgressWidget extends State<ProgressWidget>
|
|
with TickerProviderStateMixin {
|
|
late AnimationController controller;
|
|
bool determinate = false;
|
|
|
|
@override
|
|
void initState() {
|
|
controller = AnimationController(
|
|
/// [AnimationController]s can be created with `vsync: this` because of
|
|
/// [TickerProviderStateMixin].
|
|
vsync: this,
|
|
duration: const Duration(seconds: 2),
|
|
)..addListener(() {
|
|
setState(() {});
|
|
});
|
|
controller.repeat();
|
|
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.center,
|
|
children: <Widget>[
|
|
const Text(
|
|
'Linear progress indicator',
|
|
style: TextStyle(fontSize: 20),
|
|
),
|
|
const SizedBox(height: 30),
|
|
LinearProgressIndicator(
|
|
value: controller.value,
|
|
semanticsLabel: 'Linear progress indicator',
|
|
),
|
|
const SizedBox(height: 10),
|
|
Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: Text(
|
|
'determinate Mode',
|
|
style: Theme.of(context).textTheme.titleSmall,
|
|
),
|
|
),
|
|
Switch(
|
|
value: determinate,
|
|
onChanged: (bool value) {
|
|
setState(() {
|
|
determinate = value;
|
|
if (determinate) {
|
|
controller.stop();
|
|
} else {
|
|
controller
|
|
..forward(from: controller.value)
|
|
..repeat();
|
|
}
|
|
});
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|