Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can not choose a country #37

Closed
ilya-sh-dev opened this issue Apr 23, 2020 · 3 comments
Closed

I can not choose a country #37

ilya-sh-dev opened this issue Apr 23, 2020 · 3 comments
Labels
question Further information is requested

Comments

@ilya-sh-dev
Copy link

In the last update I can not choose another country

@natintosh
Copy link
Owner

@illiashvedov the package seems to work well on my end could you pls provide more information

@natintosh natintosh added the question Further information is requested label Apr 23, 2020
@ilya-sh-dev
Copy link
Author

Hi @natintosh

import 'package:flutter/material.dart';
import 'package:intl_phone_number_input/intl_phone_number_input.dart';

import 'package:my_project/assets/colors/colors.dart';
import 'package:my_project/localizations.dart';
import 'package:my_project/widgets/phone_number_input/const.dart';

class PhoneNumberInput extends StatefulWidget {
  PhoneNumberInput({
    Key key,
    @required this.focusNode,
    @required this.onSubmit,
    @required this.onInputChanged,
    this.inputDecoration,
    this.hintText,
    this.keyboardAction = TextInputAction.next,
    this.phoneNumber,
    this.autoValidate = false,
    TextStyle textStyle,
    TextEditingController textEditingController,
  })  : assert(focusNode != null),
        assert(onSubmit != null),
        assert(onInputChanged != null),
        textStyle = textStyle ?? TextStyle(fontSize: 20, color: greyColor),
        textEditingController =
            textEditingController ?? TextEditingController(),
        super(key: key);

  final FocusNode focusNode;
  final VoidCallback onSubmit;
  final ValueChanged<String> onInputChanged;
  final InputDecoration inputDecoration;
  final TextStyle textStyle;
  final String hintText;
  final String phoneNumber;
  final TextInputAction keyboardAction;
  final TextEditingController textEditingController;
  final bool autoValidate;

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

class _PhoneNumberInputState extends State<PhoneNumberInput> {
  PhoneNumber _initialPhoneNumber;

  @override
  void initState() {
    if (widget.phoneNumber != null) {
      _parsablePhoneNumber(widget.phoneNumber);
    }

    super.initState();
  }

  Future _parsablePhoneNumber(String phoneNumber) async {
    if (phoneNumber.isNotEmpty) {
      PhoneNumber numberRegionInfo =
          await PhoneNumber.getRegionInfoFromPhoneNumber(phoneNumber);

      setState(() {
        _initialPhoneNumber = numberRegionInfo;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    final local = CarWashLocalizations.of(context);

    return InternationalPhoneNumberInput(
      textFieldController: widget.textEditingController,
      countries: countries,
      textStyle: widget.textStyle,
      hintText: widget.hintText,
      errorMessage: local.invalidPhoneNumber,
      keyboardAction: widget.keyboardAction,
      initialValue: _initialPhoneNumber,
      selectorType: PhoneInputSelectorType.DIALOG,
      inputDecoration: widget.inputDecoration,
      onInputChanged: _onInputChanged,
      ignoreBlank: true,
      focusNode: widget.focusNode,
      onSubmit: widget.onSubmit,
      autoValidate: widget.autoValidate,
    );
  }

  void _onInputChanged(PhoneNumber phoneNumber) =>
      widget.onInputChanged(phoneNumber.phoneNumber);
}

As you can see, I have a wrapper for your class, it is possible that it will explicitly null as the value passed to your class, after null gets there I cannot change the country, and also I can`t enter any values. I don’t exclude that I can do something wrong

@ilya-sh-dev
Copy link
Author

Oh please forgive me, because I just realized that this is my personal problem with my project, I just made a new project and this problem did not reproduce, I apologize for the extra nerves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants