Voy a mostrar un ejemplo de cómo personalizar un loader para que aparezca en el momento que necesitemos cargar datos en nuestra aplicación.

El elemento loader es el siguiente.
class Loader extends StatelessWidget { @override Widget build(BuildContext context) { return Center( child: Container( padding: EdgeInsets.all(16.0), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(10.0), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.1), blurRadius: 10.0, offset: Offset(0, 5), ), ], ), child: Column( mainAxisSize: MainAxisSize.min, children: [ CircularProgressIndicator( valueColor: AlwaysStoppedAnimation<Color>(Colors.purple), backgroundColor: Colors.teal, strokeWidth: 4, ), SizedBox(height: 16.0), Text( 'Cargando...', style: TextStyle( fontSize: 16.0, fontWeight: FontWeight.bold, ), ), ], ), ), ); } }
Para customizar los colores y la anchura del elemento loader, debemos centrarnos en la siguiente parte del código.
CircularProgressIndicator( valueColor: AlwaysStoppedAnimation<Color>(Colors.purple), backgroundColor: Colors.teal, strokeWidth: 4, ),
A continuación muestro el código completo.
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Demo para DevCodeLight', theme: ThemeData( primarySwatch: Colors.blue, ), home: HomePage(), ); } } class HomePage extends StatelessWidget { void fetchData() async { await Future.delayed(Duration(seconds: 2)); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Demo para DevCodeLight'), ), body: Center( child: ElevatedButton( onPressed: () { showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return Dialog( backgroundColor: Colors.transparent, elevation: 0, child: Loader(), ); }, ); Future.delayed(Duration(seconds: 2), () { Navigator.pop( context); // Cerrar el diálogo del loader después de 2 segundos (simulación) }); }, child: Text('Cargar Datos'), ), ), ); } } class Loader extends StatelessWidget { @override Widget build(BuildContext context) { return Center( child: Container( padding: EdgeInsets.all(16.0), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(10.0), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.1), blurRadius: 10.0, offset: Offset(0, 5), ), ], ), child: Column( mainAxisSize: MainAxisSize.min, children: [ CircularProgressIndicator( valueColor: AlwaysStoppedAnimation<Color>(Colors.purple), backgroundColor: Colors.teal, strokeWidth: 4, ), SizedBox(height: 16.0), Text( 'Cargando...', style: TextStyle( fontSize: 16.0, fontWeight: FontWeight.bold, ), ), ], ), ), ); } }
Espero que les sirva de ayuda, feliz día!
