Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
cómo agregar cargador cuando está en el botón de alternar

Quiero mostrar un cargador circular cuando el usuario va al botón de alternar, luego, después de unos segundos, el botón de alternar se activará.

aquí está mi código

 InkWell( onTap: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) => ProductProfile(), )); }, child: Container( decoration: BoxDecoration( color: _selectedProducts.contains(book.id) ? Colors.grey[200] :Colors.white, borderRadius: BorderRadius.all( Radius.circular(10), ), ), child: ListTile( dense: true, trailing: Switch( value: _selectedProducts.contains(book.id), onChanged: (bool? selected) { if (selected != null) { setState(() { _onProductSelected(selected, book.id); }); } }, activeTrackColor: HexColor("#b8c2cc"), activeColor: HexColor("#7367f0"), ), title: Text( book.title,), Divider() ), ), ), SizedBox10(), ], );

por favor ayuda como hacer esto

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Para lograrlo, necesita bool _isLoading y un timer . Pasos que haría:

  • Declare _isLoading: bool _isLoading = false;

  • Cambie el valor de _isLoading usando un temporizador:

     void timer() { int _time = 10; Timer timer = new Timer.periodic( Duration(seconds: 1), (Timer timer) async { if (_time == 0) { _isLoading = true; timer.cancel(); } else { setState(() { _time--; }); } }, ); }
  • Use _isLoading en su método de compilación (por ejemplo):

     @override Widget build(BuildContext context) { return _isLoading ? CircularProgressIndicator() : Container(); }
  • O para ocultar su botón:

     @override Widget build(BuildContext context) { return _isLoading ? Container() : YourToggleButton; }
  • ¡Recuerde también desechar su temporizador!

     @override void dispose() { timer.cancel(); }
over 4 years ago · Santiago Trujillo Report

0

Entonces, si está en Flutter web, hay un widget llamado MouseRegion que tiene onHover , onEnter y onExit .

Puede asignar un bool nuevo, por ejemplo, bool showLoader=false , que cambiará a verdadero con setState (dentro de onHover , donde también podría iniciar el Timer y, cuando termine, restablecer el showLoader a falso).

Ahora puede mostrar su botón con un operador ternario: showLoader ? CircularProgressIndicator() : YourButton()

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!