s_dropdown 1.0.0 copy "s_dropdown: ^1.0.0" to clipboard
s_dropdown: ^1.0.0 copied to clipboard

A Flutter package for s_dropdown functionality

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:s_dropdown/s_dropdown.dart';
import 'package:sizer/sizer.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return Sizer(builder: (context, orientation, deviceType) {
      return MaterialApp(
        title: 'SDropdown Example',
        home: const ExampleHome(),
      );
    });
  }
}

class ExampleHome extends StatefulWidget {
  const ExampleHome({super.key});

  @override
  State<ExampleHome> createState() => _ExampleHomeState();
}

class _ExampleHomeState extends State<ExampleHome> {
  final List<String> _items = ['Apple', 'Banana', 'Cherry', 'Durian'];
  String? _selected;
  final SDropdownController _controller = SDropdownController();
  final SDropdownController _controller2 = SDropdownController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('SDropdown Example')),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const SizedBox(height: 16),
            // Basic usage
            SDropdown(
              items: _items,
              selectedItem: _selected,
              hintText: 'Select a fruit',
              onChanged: (value) {
                setState(() {
                  _selected = value;
                });
              },
              width: 280,
              height: 52,
              controller: _controller,
            ),
            const SizedBox(height: 20),
            // Decorated dropdown with overlay size override
            SDropdown(
              items: _items,
              selectedItem: _selected,
              hintText: 'Decorated dropdown',
              onChanged: (value) {
                setState(() {
                  _selected = value;
                });
              },
              width: 300,
              height: 55,
              overlayWidth: 350,
              overlayHeight: 180,
              decoration: SDropdownDecoration(
                closedFillColor: Colors.grey.shade200,
                expandedFillColor: Colors.white,
                closedBorder: Border.all(color: Colors.grey.shade400),
                expandedBorder:
                    Border.all(color: Colors.blue.shade700, width: 1.5),
                closedBorderRadius: BorderRadius.circular(10),
                expandedBorderRadius: BorderRadius.circular(8),
                headerStyle:
                    const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
                hintStyle: const TextStyle(fontSize: 16, color: Colors.grey),
                listItemStyle: const TextStyle(fontSize: 14),
              ),
            ),
            const SizedBox(height: 20),
            // Exclude selected from overlay & custom items
            SDropdown(
              items: _items,
              selectedItem: _selected,
              hintText: 'Exclude selected',
              onChanged: (value) {
                setState(() {
                  _selected = value;
                });
              },
              width: 260,
              height: 48,
              excludeSelected: true,
              customItemsNamesDisplayed: [
                '🍎 Apple',
                '🍌 Banana',
                '🍒 Cherry',
                '💥 Durian'
              ],
            ),
            const SizedBox(height: 20),
            // Custom header text to display friendly label for the selected value
            SDropdown(
              items: _items,
              selectedItem: 'Apple',
              selectedItemText: '🍎 Apple',
              hintText: 'Selected text override',
              width: 260,
              height: 48,
            ),
            const SizedBox(height: 20),
            // Validator + item specific style + responsive sizing
            Form(
              child: SDropdown(
                items: _items,
                selectedItem: _selected,
                hintText: 'With validator & item styles (60% width)',
                onChanged: (value) {
                  setState(() {
                    _selected = value;
                  });
                },
                width: 60.w,
                height: 6.h,
                validator: (v) => v == null ? 'Please select' : null,
                validateOnChange: true,
                itemSpecificStyles: {
                  'Durian': const TextStyle(
                      color: Colors.deepPurple, fontWeight: FontWeight.bold),
                },
              ),
            ),
            const SizedBox(height: 20),
            // Controller demonstration with programmatic navigation
            SDropdown(
              items: _items,
              hintText: 'Controller demo',
              width: 260,
              height: 48,
              controller: _controller2,
            ),
            const SizedBox(height: 12),
            Row(
              children: [
                ElevatedButton(
                  onPressed: () => _controller2.open(),
                  child: const Text('Open'),
                ),
                const SizedBox(width: 12),
                ElevatedButton(
                  onPressed: () => _controller2.highlightNext(),
                  child: const Text('Highlight Next'),
                ),
                const SizedBox(width: 12),
                ElevatedButton(
                  onPressed: () => _controller2.selectHighlighted(),
                  child: const Text('Select Highlighted'),
                ),
              ],
            ),
            Row(
              children: [
                ElevatedButton(
                  onPressed: () => _controller.open(),
                  child: const Text('Open'),
                ),
                const SizedBox(width: 12),
                ElevatedButton(
                  onPressed: () => _controller.close(),
                  child: const Text('Close'),
                ),
                const SizedBox(width: 12),
                ElevatedButton(
                  onPressed: () => _controller.toggle(),
                  child: const Text('Toggle'),
                ),
              ],
            ),
            const SizedBox(height: 20),
            Text('Selected value: ${_selected ?? "(none)"}'),
          ],
        ),
      ),
    );
  }
}
0
likes
0
points
118
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for s_dropdown functionality

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

assorted_layout_widgets, flutter, indexscroll_listview_builder, sizer, soundsliced_tween_animation_builder

More

Packages that depend on s_dropdown