📄
FlutterCheatSheet
  • About
  • Flutter web
    • Download in flutter web
    • Fluter run web selain chrome
    • Mengatasi CORS
  • My Note
    • Cara mudah setting Firebase
    • solusi text overflow
    • Setting Firebase Mobile
    • Setting MinSDK Android
    • Run build runner
    • Load Json FromAsset
    • Set Height TabBar
    • WillPopScope
    • Dropdown with null
    • Interview Flutter
    • shortcut android studio
    • Build with different main.dart
    • Validating email
    • search delay
    • Hive
    • penggunaan sort maupun func lain
    • incompatible version of Kotlin.
    • Google Signin error
    • add Map to Map
    • Cors Anywhere
    • run scrcpy simple
    • android studio adb server version (41) doesn't match this client (39); killing
    • Connect adb with hotspot
    • Bloc , intinya...
    • Restorable state
    • Custom Theme DatePicker Flutter
    • membungkus widget dengan tema
    • All About Extention
    • Provider watch read
    • Provider , App works in debug mode but does not work in release mode
    • make extention
    • Sliver app bar
    • Custom Error screen
    • Rename Package
    • error build on AndroidStudio from vscode
    • add tooltip to all widget
    • Textformfield validator
    • Membuat String Rupiah
    • Sort List Dart
    • chart
    • membuat Date time lokal
    • Change default PageTransition
    • Show Hide Password
    • Error UserFriendly
    • Responsive adaptive layout
    • Tips SingleScrollingView
    • Build context
    • FittedBox
    • validation
      • Dropdown validation
    • alertDialog
      • Mixin
      • FocusNode
      • WebView url listener
      • tips statefull pada alertdialog
      • run-code-after-showdialog-is-dismissed
    • Set package in VS Code when creating a project
  • Usefull source
    • Setting JAVA_HOME
    • Tools for Flutter
    • WEBVIEW
    • membuat Marque
    • LazyLoad
    • Tips
      • Penggunaan Const
      • 3 Dots
      • How Disable all Widget
    • List article
    • List Web Complete Tutorial
    • List library
    • Parsing nested Json
    • Future
      • Tips Clean Code
      • Custom Future
      • Chaining Future
      • Catch error
    • Flutter Sample HTTP Request Github with https://reqres.in/
    • Const vs Final
    • Constructor
    • Function
    • Font
    • CRUD
    • Key
    • Free bootcamp
    • State Manajement
      • Provider
  • Widgets
    • Top 5 Box widget
    • Framework library
      • GetFlutter
      • FLUI
    • kumpulan widget
      • Spacer
      • ClipRRect
      • Switch
      • FittedBox
      • List dari Model
      • Dropdown
        • DropDown Multi
    • Deep Dive
      • Button
      • Card
      • Flexible and Expanded
      • Layout Builder
  • Interview Question
    • Kumpulan Pertannyaan Interview
      • Interview Question link Flutter
      • Interview Question With Answer
  • kasus dari stackoverflow
    • Text Red in Hero
    • firebase issued
    • Untitled
  • library
    • Rapido
    • autoscroll text
Powered by GitBook
On this page

Was this helpful?

  1. My Note

Dropdown with null

Custom dropdown with null value

import 'package:flutter/material.dart';
import 'package:survey_jalan_apps/theme/theme.dart';
class CustomDropDown extends StatelessWidget {
  final String? selected;
  final String? label;
  final List<String>? list;
  final Function(String?)? onChanged;

  const CustomDropDown({
    Key? key,
    this.selected,
    this.label,
    this.list,
    this.onChanged,
  }) : super(key: key);
  getSelectedValue(String? yourValue, List<String> dropDownItems){
    //add this line of code
    if(yourValue == null) return null;
    for(String value in dropDownItems){
      if(value == yourValue) return value;
    }
    return null;
  }
  @override
  Widget build(BuildContext context) {
    return Card(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: EdgeInsets.all(4),
            width: double.infinity,
            decoration: BoxDecoration(
              color: Theme.of(context).primaryColorLight,
              borderRadius: BorderRadius.only(
                topRight: Radius.circular(15),
                topLeft: Radius.circular(15),
              ),
            ),
            child: Text(
              label!,
              style: myTextTheme.headline6,
              textAlign: TextAlign.center,
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: DropdownButton<String>(
              hint: Center(child: Text('---',textAlign: TextAlign.center)),
              isExpanded: true,
              isDense: true,
              underline: Text(''),
              value: getSelectedValue(selected,list!),
              onChanged: onChanged,
              items: list?.map<DropdownMenuItem<String>>((String value) {
                return DropdownMenuItem<String>(
                  value: value,
                  child: Center(child: Text(value,textAlign: TextAlign.center,)),
                );
              }).toList(),
            ),
          ),
        ],
      ),
    );
  }
}
PreviousWillPopScopeNextInterview Flutter

Last updated 3 years ago

Was this helpful?