open:admin_dropdown.dart

admin_dropdown.dart

import 'package:app_screen_flutter/view/admin/home/atom/border_text.dart';
import 'package:flutter/material.dart';
 
class AdminDropdown<T> extends StatelessWidget {
  const AdminDropdown({
    super.key,
    this.width = 500,
    this.title = "",
    required this.value,
    required this.items,
    required this.onChanged,
    required this.itemBuilder,
  });
  final String title;
  final double width;
  final T? value;
  final List<T> items;
  final Function(T?) onChanged;
  final Function(T) itemBuilder;
 
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          BorderText(title, border: true),
          const SizedBox(width: 10),
          DropdownButton<T>(
            value: value,
            items: items
                .map((T e) => DropdownMenuItem<T>(
                      value: e,
                      child: itemBuilder(e),
                    ))
                .toList(),
            onChanged: onChanged,
          )
        ],
      ),
    );
  }
}

AdminDropdown<Service>(
  title: 'service',
  value: controller.service.value,
  items: ServiceService.to.serviceList,
  itemBuilder: (Service e) => Text(e.name),
  onChanged: (Service? e) {
    if (e != null) controller.selectService(e);
  },
),

  • open/admin_dropdown.dart.txt
  • 마지막으로 수정됨: 2023/04/17 04:42
  • 저자 MORO