| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:google_fonts/google_fonts.dart';
- class Cargando extends StatefulWidget {
- final String text;
- const Cargando({
- Key? key,
- required this.text
- }) : super (key: key);
- @override
- _CargandoState createState() => _CargandoState();
- }
- class _CargandoState extends State<Cargando> {
- late Timer _timer;
- int _start = 3;
- void _startTimer(){
- const oneSec = Duration(
- seconds: 1,
- );
- _timer = Timer.periodic(
- oneSec,
- (timer){
- if(_start == 0){
- setState((){
- _start = 3;
- });
- }else if(_start == 2){
- setState((){
- _start--;
- });
- }else{
- setState(() => _start--);
- }
- }
- );
- }
- @override
- void dispose() {
- super.dispose();
- _timer.cancel();
- }
- @override
- void initState() {
- super.initState();
- _startTimer();
- }
- @override
- Widget build(BuildContext context) {
- return AnimatedCrossFade(
- firstChild: Text(
- widget.text,
- textAlign: TextAlign.center,
- style: GoogleFonts.robotoSlab(
- fontWeight: FontWeight.bold,
- color: const Color(0xFFB40404),
- fontSize: 16.0,
- ),
- ),
- secondChild: Text(
- widget.text,
- textAlign: TextAlign.center,
- style: GoogleFonts.robotoSlab(
- fontWeight: FontWeight.bold,
- color: const Color(0x55B40404),
- fontSize: 16.0,
- ),
- ),
- duration: const Duration(
- seconds: 2,
- ),
- crossFadeState: _start > 0 && _start <= 2 ? CrossFadeState.showFirst : CrossFadeState.showSecond,
- );
- }
- }
|