123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import 'package:flutter/material.dart';
- import 'package:flutter_habit/common/I18N.dart';
- class SliderConfirm extends StatefulWidget {
- final Function function;
- SliderConfirm({required this.function});
- @override
- _SliderConfirmState createState() => _SliderConfirmState();
- }
- class _SliderConfirmState extends State<SliderConfirm> {
- double? currentValue;
- late bool isEnd;
- late bool isFormStart;
- @override
- void initState() {
-
- super.initState();
- currentValue = 0;
- isEnd = false;
- isFormStart = false;
- }
- @override
- Widget build(BuildContext context) {
- return Stack(
- children: <Widget>[
- Center(
- child: Container(
- decoration: BoxDecoration(
- color: Theme.of(context).focusColor,
- borderRadius: BorderRadius.circular(100),
- ),
- child: Slider(
- activeColor: Theme.of(context).colorScheme.secondary,
- inactiveColor: Colors.transparent,
- value: currentValue!,
- min: 0,
- max: 1,
- onChanged: (value) {
- if (value <= 0.1) {
- currentValue = value;
- isFormStart = true;
- setState(() {});
- }
- if (isFormStart) {
- currentValue = value;
- isEnd = currentValue == 1;
- setState(() {});
- }
- },
- onChangeEnd: (value) {
- if (isEnd) {
- widget.function();
- } else {
- isFormStart = false;
- currentValue = 0;
- setState(() {});
- }
- },
- ),
- ),
- ),
- Center(
- child: isEnd
- ? Text(
- I18N.of("松开以继续"),
- style: Theme.of(context)
- .textTheme
- .titleSmall!
- .copyWith(color: Theme.of(context).colorScheme.secondary),
- )
- : Text(
- I18N.of("向右滑动"),
- style: Theme.of(context).textTheme.titleLarge,
- ),
- ),
- ],
- );
- }
- }
|