load_switch 3.0.0
load_switch: ^3.0.0 copied to clipboard
A highly customizable toggle switch with a loading state. Useful when getting data from remote calls.
import 'package:example/styles/controller_example.dart';
import 'package:example/styles/custom_example.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: ExampleSelector()));
}
class ExampleSelector extends StatelessWidget {
const ExampleSelector({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('LoadSwitch Examples'),
backgroundColor: Colors.indigo,
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Choose an example to explore:',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
const SizedBox(height: 30),
_buildExampleCard(
context,
'Controller Example',
'Shows how to drive the switch with an external controller.',
Icons.settings,
Colors.blue,
const LoadSwitchControllerExample(),
),
const SizedBox(height: 16),
_buildExampleCard(
context,
'Custom Styling',
'Examples of custom styling, decorations, and animations.',
Icons.palette,
Colors.purple,
const CustomStyleExample(),
),
],
),
),
);
}
Widget _buildExampleCard(
BuildContext context,
String title,
String description,
IconData icon,
Color color,
Widget destination,
) {
return Card(
elevation: 4,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => destination),
);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(icon, color: color, size: 30),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
description,
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
),
],
),
),
Icon(Icons.arrow_forward_ios, color: Colors.grey[400]),
],
),
),
),
);
}
}