Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="language_pickers_demo"
android:label="language_pickers_demo" android:theme="@style/LaunchTheme"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand All @@ -23,10 +22,15 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="flutterEmbedding"
android:value="2" />

<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->

<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
28 changes: 14 additions & 14 deletions lib/language_picker_cupertino.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const double defaultPickerItemHeight = 32.0;
/// in cupertino style
class LanguagePickerCupertino extends StatefulWidget {
/// Callback that is called with selected Language
final ValueChanged<Language> onValuePicked;
final ValueChanged<Language>? onValuePicked;

///Callback that is called with selected item of type Language which returns a
///Widget to build list view item inside dialog
final ItemBuilder itemBuilder;
final ItemBuilder? itemBuilder;

///The [itemExtent] of [CupertinoPicker]
/// The uniform height of all children.
Expand All @@ -26,7 +26,7 @@ class LanguagePickerCupertino extends StatefulWidget {
final double pickerSheetHeight;

///The TextStyle that is applied to Text widgets inside item
final TextStyle textStyle;
final TextStyle? textStyle;

/// Relative ratio between this picker's height and the simulated cylinder's diameter.
///
Expand All @@ -35,35 +35,35 @@ class LanguagePickerCupertino extends StatefulWidget {
/// For more details, see [ListWheelScrollView.diameterRatio].
///
/// Must not be null and defaults to `1.1` to visually mimic iOS.
final double diameterRatio;
final double? diameterRatio;

/// Background color behind the children.
///
/// Defaults to a gray color in the iOS color palette.
///
/// This can be set to null to disable the background painting entirely; this
/// is mildly more efficient than using [Colors.transparent].
final Color backgroundColor;
final Color? backgroundColor;

/// {@macro flutter.rendering.wheelList.offAxisFraction}
final double offAxisFraction;
final double? offAxisFraction;

/// {@macro flutter.rendering.wheelList.useMagnifier}
final bool useMagnifier;
final bool? useMagnifier;

/// {@macro flutter.rendering.wheelList.magnification}
final double magnification;
final double? magnification;

/// A [FixedExtentScrollController] to read and control the current item.
///
/// If null, an implicit one will be created internally.
final FixedExtentScrollController scrollController;
final FixedExtentScrollController? scrollController;

/// List of languages available in this picker.
final List<Map<String, String>> languagesList;
final List<Map<String, String>>? languagesList;

const LanguagePickerCupertino({
Key key,
Key? key,
this.onValuePicked,
this.itemBuilder,
this.pickerItemHeight = defaultPickerItemHeight,
Expand All @@ -83,7 +83,7 @@ class LanguagePickerCupertino extends StatefulWidget {
}

class _CupertinoLanguagePickerState extends State<LanguagePickerCupertino> {
List<Language> _allLanguages;
late List<Language> _allLanguages;

@override
void initState() {
Expand Down Expand Up @@ -124,11 +124,11 @@ class _CupertinoLanguagePickerState extends State<LanguagePickerCupertino> {
backgroundColor: CupertinoColors.white,
children: _allLanguages
.map<Widget>((Language language) => widget.itemBuilder != null
? widget.itemBuilder(language)
? widget.itemBuilder!(language)
: _buildDefaultItem(language))
.toList(),
onSelectedItemChanged: (int index) {
widget.onValuePicked(_allLanguages[index]);
widget.onValuePicked!(_allLanguages[index]);
},
);
}
Expand Down
30 changes: 15 additions & 15 deletions lib/language_picker_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import 'languages.dart';

class LanguagePickerDialog extends StatefulWidget {
/// Callback that is called with selected Language
final ValueChanged<Language> onValuePicked;
final ValueChanged<Language>? onValuePicked;

/// The (optional) title of the dialog is displayed in a large font at the top
/// of the dialog.
///
/// Typically a [Text] widget.
final Widget title;
final Widget? title;

/// Padding around the title.
///
Expand All @@ -29,7 +29,7 @@ class LanguagePickerDialog extends StatefulWidget {
/// provided (but see [contentPadding]). If it _is_ null, then an extra 20
/// pixels of bottom padding is added to separate the [title] from the
/// [actions].
final EdgeInsetsGeometry titlePadding;
final EdgeInsetsGeometry? titlePadding;

/// Padding around the content.

Expand All @@ -46,11 +46,11 @@ class LanguagePickerDialog extends StatefulWidget {
///
/// * [SemanticsConfiguration.isRouteName], for a description of how this
/// value is used.
final String semanticLabel;
final String? semanticLabel;

///Callback that is called with selected item of type Language which returns a
///Widget to build list view item inside dialog
final ItemBuilder itemBuilder;
final ItemBuilder? itemBuilder;

/// The (optional) horizontal separator used between title, content and
/// actions.
Expand All @@ -67,19 +67,19 @@ class LanguagePickerDialog extends StatefulWidget {
final bool isSearchable;

/// The optional [decoration] of search [TextField]
final InputDecoration searchInputDecoration;
final InputDecoration? searchInputDecoration;

///The optional [cursorColor] of search [TextField]
final Color searchCursorColor;
final Color? searchCursorColor;

///The search empty view is displayed if nothing returns from search result
final Widget searchEmptyView;
final Widget? searchEmptyView;

/// List of languages available in this picker.
final List<Map<String, String>> languagesList;
final List<Map<String, String>>? languagesList;

LanguagePickerDialog({
Key key,
Key? key,
this.onValuePicked,
this.title,
this.titlePadding,
Expand All @@ -104,8 +104,8 @@ class LanguagePickerDialog extends StatefulWidget {
}

class SingleChoiceDialogState extends State<LanguagePickerDialog> {
List<Language> _allLanguages;
List<Language> _filteredLanguages;
late List<Language> _allLanguages;
late List<Language> _filteredLanguages;

@override
void initState() {
Expand Down Expand Up @@ -134,10 +134,10 @@ class SingleChoiceDialogState extends State<LanguagePickerDialog> {
children: _filteredLanguages
.map((item) => SimpleDialogOption(
child: widget.itemBuilder != null
? widget.itemBuilder(item)
? widget.itemBuilder!(item)
: Text(item.name),
onPressed: () {
widget.onValuePicked(item);
widget.onValuePicked!(item);
Navigator.pop(context);
},
))
Expand All @@ -163,7 +163,7 @@ class SingleChoiceDialogState extends State<LanguagePickerDialog> {
_buildTitle() {
return widget.titlePadding != null
? Padding(
padding: widget.titlePadding,
padding: widget.titlePadding!,
child: widget.title,
)
: widget.title;
Expand Down
18 changes: 9 additions & 9 deletions lib/language_picker_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ class LanguagePickerDropdown extends StatefulWidget {
///If it is not provided, default one will be used which displays
///flag image, isoCode and phoneCode in a row.
///Check _buildDefaultMenuItem method for details.
final ItemBuilder itemBuilder;
final ItemBuilder? itemBuilder;

///It should be one of the ISO ALPHA-2 Code that is provided
///in languagesList map of languages.dart file.
final String initialValue;
final String? initialValue;

///This function will be called whenever a Language item is selected.
final ValueChanged<Language> onValuePicked;
final ValueChanged<Language>? onValuePicked;

/// List of languages available in this picker.
final List<Map<String, String>> languagesList;
final List<Map<String, String>>? languagesList;

@override
_LanguagePickerDropdownState createState() => _LanguagePickerDropdownState();
}

class _LanguagePickerDropdownState extends State<LanguagePickerDropdown> {
List<Language> _languages;
Language _selectedLanguage;
late List<Language> _languages;
late Language _selectedLanguage;

@override
void initState() {
Expand Down Expand Up @@ -58,7 +58,7 @@ class _LanguagePickerDropdownState extends State<LanguagePickerDropdown> {
.map((language) => DropdownMenuItem<Language>(
value: language,
child: widget.itemBuilder != null
? widget.itemBuilder(language)
? widget.itemBuilder!(language)
: _buildDefaultMenuItem(language)))
.toList();

Expand All @@ -69,8 +69,8 @@ class _LanguagePickerDropdownState extends State<LanguagePickerDropdown> {
isDense: true,
onChanged: (value) {
setState(() {
_selectedLanguage = value;
widget.onValuePicked(value);
_selectedLanguage = value!;
widget.onValuePicked!(value);
});
},
items: items,
Expand Down
4 changes: 2 additions & 2 deletions lib/languages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class Language {
final String isoCode;

Language.fromMap(Map<String, String> map)
: name = map['name'],
isoCode = map['isoCode'];
: name = map['name']!,
isoCode = map['isoCode']!;
}

final List defaultLanguagesList = [
Expand Down
Loading