riff_switch 0.0.2 copy "riff_switch: ^0.0.2" to clipboard
riff_switch: ^0.0.2 copied to clipboard

Experience seamless transitions and engaging interactions with RiffSwitch.

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:riff_switch/riff_switch.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorSchemeSeed: Colors.blue,
      ),
      debugShowCheckedModeBanner: false,
      home: const RiffSwitchExample(title: 'RiffSwitch Example Page'),
    );
  }
}

class RiffSwitchExample extends StatefulWidget {
  const RiffSwitchExample({super.key, title}) : _title = title;

  final String _title;

  @override
  State<RiffSwitchExample> createState() => _RiffSwitchExampleState();
}

class _RiffSwitchExampleState extends State<RiffSwitchExample> {
  late bool _switchValue_1 = false;
  late bool _switchValue_2 = false;
  late bool _switchValue_3 = false;
  late bool _switchValue_4 = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Theme.of(context).colorScheme.onBackground,
      appBar: AppBar(title: Text(widget._title)),
      body: Padding(
        padding: const EdgeInsets.all(30.0),
        child: Column(children: [
          const SizedBox(height: 30),

          // 1
          RiffSwitch(
            value: _switchValue_1,
            onChanged: (value) => setState(() {
              _switchValue_1 = value;
            }),
            type: RiffSwitchType.simple,
            enableSlide: false,
          ),

          const SizedBox(height: 30),

          // 2
          RiffSwitch(
            value: _switchValue_2,
            onChanged: (value) => setState(() {
              _switchValue_2 = value;
            }),
            type: RiffSwitchType.simple,
            activeText: const Text("Accept"),
            inactiveText: const Text("Decline"),
            thumbColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
              if (states.contains(MaterialState.selected)) {
                return Colors.greenAccent;
              }
              return Colors.pinkAccent;
            }),
            trackColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
              if (states.contains(MaterialState.selected)) {
                return Colors.grey;
              }
              return Colors.grey;
            }),
          ),

          const SizedBox(height: 30),

          // 3
          RiffSwitch(
            value: _switchValue_3,
            onChanged: (value) => setState(() {
              _switchValue_3 = value;
            }),
            type: RiffSwitchType.decorative,
            activeColor: Colors.orange,
          ),

          const SizedBox(height: 30),

          // 4
          RiffSwitch(
            value: _switchValue_4,
            onChanged: (value) => setState(() {
              _switchValue_4 = value;
            }),
            type: RiffSwitchType.decorative,
            activeChild: const Card(
              color: CupertinoColors.systemBlue,
              child: FlutterLogo(),
            ),
            inactiveChild: const Card(
              color: CupertinoColors.systemYellow,
              child: FlutterLogo(),
            ),
          )
        ]),
      ),
    );
  }
}
6
likes
0
pub points
76%
popularity

Publisher

unverified uploader

Experience seamless transitions and engaging interactions with RiffSwitch.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on riff_switch