簡體   English   中英

Flutter bloc provider模式更新其他畫面

[英]Flutter bloc provider pattern update other screen

我對 flutter 模式塊提供程序有問題,我有一個頁面配置文件和另一個帶有表單的頁面 profile_edit,我想在保存表單數據時更新配置文件頁面中的數據,保存表單時如何更新頁面配置文件?

這是我完整的個人資料頁面:

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:transparent_image/transparent_image.dart';
import 'package:wags/bloc/profile/bloc.dart';
import 'package:wags/bloc/profile/profile_event.dart';
import 'package:wags/custom_widgets/wags_button_azure.dart';
import 'package:wags/custom_widgets/wags_loader.dart';
import 'package:wags/pages/profile_edit/profile_edit.dart';
import 'package:wags/repositories/user_repository.dart';
import 'package:wags/utility/wagsColor.dart';

class ProfilePage extends StatefulWidget {
  final UserRepository userRepository;

  const ProfilePage({Key key, this.userRepository}) : super(key: key);

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

class _ProfilePageState extends State<ProfilePage> {

  Widget build(BuildContext context) {
    return BlocBuilder<ProfileBloc, ProfileState>(
      builder: (context, state) {
        if (state is UninitializedProfile) {
          return Center(
            child: WagsLoader(width: 30, height: 30),
          );
        } else if (state is ProfileError) {
          return Center(
            child: Text(
              'Recupero delle informazioni utente fallito',
              style: TextStyle(
                fontFamily: "AvenirNext",
                fontSize: 15,
                fontWeight: FontWeight.w400,
                color: Colors.black,
              ),
            ),
          );
        } else if (state is ProfileLoaded) {
          if (state.profile == null) {
            return Center(
              child: Text(
                'Nessuna News trovata',
                style: TextStyle(
                  fontFamily: "AvenirNext",
                  fontSize: 15,
                  fontWeight: FontWeight.w400,
                  color: Colors.black,
                ),
              ),
            );
          }
          return Scaffold(
            body: SingleChildScrollView(
              child: Container(
                child: SafeArea(
                  child: Column(
                    children: <Widget>[
                      Container(
                        padding:
                            EdgeInsets.symmetric(horizontal: 30, vertical: 20),
                        child: Column(
                          children: <Widget>[
                            Row(
                              children: <Widget>[
                                Spacer(),
                                state.profile.image == ""
                                    ? Image(
                                        width: 180,
                                        height: 180,
                                        image: AssetImage(
                                            "assets/profilo_placeholder.png"),
                                        fit: BoxFit.cover,
                                      )
                                    : ClipRRect(
                                        borderRadius:
                                            BorderRadius.circular(90.0),
                                        child: FadeInImage.memoryNetwork(
                                          fit: BoxFit.cover,
                                          width: 180,
                                          height: 180,
                                          placeholder: kTransparentImage,
                                          image:
                                              'https://projectinvictus.azurewebsites.net/userImage/${state.profile.uid}/${state.profile.image}',
                                        ),
                                      ),
                                Spacer(),
                              ],
                            ),
                            SizedBox(
                              height: 15,
                            ),
                            state.profile.isWannabe
                                ? Container(
                                    margin: EdgeInsets.only(
                                      bottom: 20,
                                    ),
                                    child: Column(
                                      children: <Widget>[
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          crossAxisAlignment:
                                              CrossAxisAlignment.end,
                                          children: <Widget>[
                                            Image(
                                              width: 31,
                                              height: 34,
                                              image: AssetImage(
                                                  "assets/wannabe_placeholder.png"),
                                              fit: BoxFit.cover,
                                            ),
                                            SizedBox(
                                              width: 5,
                                            ),
                                            Text(
                                              "Wannabe",
                                              style: TextStyle(
                                                fontFamily: "AvenirNext",
                                                fontSize: 20,
                                                fontWeight: FontWeight.w700,
                                                color: WagsColor.PrimaryColor,
                                              ),
                                            )
                                          ],
                                        ),
                                        Builder(builder: (context) {
                                          if (state.profile.isWannabe) {
                                            return Container(
                                              margin: EdgeInsets.only(top: 5),
                                              child: Text(
                                                state.profile.isPubblic ? "profilo pubblico" : "profilo privato ",
                                                style: TextStyle(
                                                  fontFamily: "AvenirNext",
                                                  fontSize: 12,
                                                  fontWeight: FontWeight.w400,
                                                  color: WagsColor
                                                      .PrimaryGreyColor,
                                                ),
                                              ),
                                            );
                                          } else {
                                            return Container();
                                          }
                                        }),
                                      ],
                                    ),
                                  )
                                : Container(),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Text(
                                  state.profile.fullname,
                                  style: TextStyle(
                                    fontFamily: "AvenirNext",
                                    fontSize: 27,
                                    fontWeight: FontWeight.w700,
                                    color: Colors.black,
                                  ),
                                ),
                                SizedBox(
                                  width: 10,
                                ),
                                InkWell(
                                  onTap: () {

                                    Navigator.push(
                                      context,
                                      MaterialPageRoute(
                                        builder: (context) =>
                                            ProfileEditMainPage(user: state.profile,),
                                      ),
                                    );
                                  },
                                  child: Icon(
                                    FontAwesomeIcons.edit,
                                    color: WagsColor.PrimaryColor,
                                    size: 20,
                                  ),
                                ),
                              ],
                            ),
                            SizedBox(
                              height: 10,
                            ),
                            Builder(builder: (context) {
                              if (state.profile.city != "" && state.profile.nationality == "") {
                                return Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: <Widget>[
                                    Text(
                                      state.profile.city,
                                      style: TextStyle(
                                        fontFamily: "AvenirNext",
                                        fontSize: 17,
                                        fontWeight: FontWeight.w400,
                                        color: WagsColor.PrimaryGreyColor,
                                      ),
                                    ),
                                  ],
                                );
                              } else if (state.profile.city == "" && state.profile.nationality != "") {
                                return Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: <Widget>[
                                    Text(
                                      state.profile.nationality,
                                      style: TextStyle(
                                        fontFamily: "AvenirNext",
                                        fontSize: 17,
                                        fontWeight: FontWeight.w400,
                                        color: WagsColor.PrimaryGreyColor,
                                      ),
                                    ),
                                  ],
                                );
                              } else if (state.profile.city != "" && state.profile.nationality != "") {
                                return Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: <Widget>[
                                    Text(
                                      "${state.profile.city}, ${state.profile.nationality}",
                                      style: TextStyle(
                                        fontFamily: "AvenirNext",
                                        fontSize: 17,
                                        fontWeight: FontWeight.w400,
                                        color: WagsColor.PrimaryGreyColor,
                                      ),
                                    ),
                                  ],
                                );
                              } else {
                                return Container();
                              }
                            }),
                            state.profile.description != ""
                                ? Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: <Widget>[
                                      Container(
                                        margin: EdgeInsets.only(
                                            top: 20, bottom: 20),
                                        child: Text(
                                          state.profile.description,
                                          style: TextStyle(
                                            fontFamily: "AvenirNext",
                                            fontSize: 15,
                                            fontWeight: FontWeight.w400,
                                            color: Colors.black,
                                          ),
                                        ),
                                      ),
                                    ],
                                  )
                                : Container(),
                            Column(
                              children: <Widget>[
                                state.profile.linkInstagram != ""
                                    ? Container(
                                        margin: EdgeInsets.only(
                                          bottom: 5,
                                        ),
                                        child: Row(
                                          children: <Widget>[
                                            Icon(
                                              FontAwesomeIcons.instagram,
                                              color: Colors.black,
                                              size: 20,
                                            ),
                                            SizedBox(
                                              width: 10,
                                            ),
                                            Text(
                                              "@${state.profile.linkInstagram}",
                                              style: TextStyle(
                                                fontFamily: "AvenirNext",
                                                fontSize: 15,
                                                fontWeight: FontWeight.w600,
                                                color: Colors.black,
                                              ),
                                            ),
                                          ],
                                        ),
                                      )
                                    : Container(),
                                state.profile.linkFacebook != ""
                                    ? Container(
                                        margin: EdgeInsets.only(
                                          bottom: 5,
                                        ),
                                        child: Row(
                                          children: <Widget>[
                                            Icon(
                                              FontAwesomeIcons.facebook,
                                              color: Colors.black,
                                              size: 20,
                                            ),
                                            SizedBox(
                                              width: 10,
                                            ),
                                            Text(
                                              "@${state.profile.linkFacebook}",
                                              style: TextStyle(
                                                fontFamily: "AvenirNext",
                                                fontSize: 15,
                                                fontWeight: FontWeight.w600,
                                                color: Colors.black,
                                              ),
                                            ),
                                          ],
                                        ),
                                      )
                                    : Container(),
                                state.profile.linkTwitter != ""
                                    ? Container(
                                        child: Row(
                                          children: <Widget>[
                                            Icon(
                                              FontAwesomeIcons.twitter,
                                              color: Colors.black,
                                              size: 20,
                                            ),
                                            SizedBox(
                                              width: 10,
                                            ),
                                            Text(
                                              "@${state.profile.linkTwitter}",
                                              style: TextStyle(
                                                fontFamily: "AvenirNext",
                                                fontSize: 15,
                                                fontWeight: FontWeight.w600,
                                                color: Colors.black,
                                              ),
                                            ),
                                          ],
                                        ),
                                      )
                                    : Container(),
                              ],
                            ),
                          ],
                        ),
                      ),
                      Divider(),
                      Container(
                        padding:
                            EdgeInsets.symmetric(horizontal: 30, vertical: 20),
                        child: Row(
                          children: <Widget>[
                            Spacer(),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Text(
                                  "4325",
                                  style: TextStyle(
                                    fontFamily: "AvenirNext",
                                    fontSize: 27,
                                    fontWeight: FontWeight.w600,
                                    color: Colors.black87,
                                  ),
                                ),
                                Text(
                                  "Followers",
                                  style: TextStyle(
                                    fontFamily: "AvenirNext",
                                    fontSize: 12,
                                    fontWeight: FontWeight.w400,
                                    color: WagsColor.PrimaryGreyColor,
                                  ),
                                ),
                              ],
                            ),
                            Spacer(),
                            Column(
                              children: <Widget>[
                                Text(
                                  "7281",
                                  style: TextStyle(
                                    fontFamily: "AvenirNext",
                                    fontSize: 27,
                                    fontWeight: FontWeight.w600,
                                    color: Colors.black87,
                                  ),
                                ),
                                Text(
                                  "Following",
                                  style: TextStyle(
                                    fontFamily: "AvenirNext",
                                    fontSize: 12,
                                    fontWeight: FontWeight.w400,
                                    color: WagsColor.PrimaryGreyColor,
                                  ),
                                ),
                              ],
                            ),
                            Spacer()
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.only(left: 30, right: 30),
                        child: Column(
                          children: <Widget>[
                            Builder(builder: (context) {
                              if (state.profile.gender != "Uomo" &&
                                  state.profile.isWannabe == false) {
                                return SizedBox(
                                  height: 15,
                                );
                              } else {
                                return Container();
                              }
                            }),
                            Builder(builder: (context) {
                              if (state.profile.gender != "Uomo" &&
                                  state.profile.isWannabe == false) {
                                return WagsButtonAzure(
                                  buttonText: "Diventa Aspirante WAGS",
                                  onPressed: null,
                                );
                              } else {
                                return Container();
                              }
                            }),
                            Builder(builder: (context) {
                              if (state.profile.gender != "Uomo" &&
                                  state.profile.isWannabe == false) {
                                return SizedBox(
                                  height: 15,
                                );
                              } else {
                                return Container();
                              }
                            }),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          );
        } else {
          return Center(
            child: WagsLoader(width: 30, height: 30),
          );
        }
      },
    );
  }
}

我已經嘗試過了,但頁面配置文件無法重新加載數據:

if (state.isSuccess) {
          BlocProvider.of<ProfileBloc>(context).add(UninitializedProfile());
          Navigator.of(context).pop();
        }

非常感謝您的幫助。

這是個人資料編輯:

class ProfileEditMainPage extends StatelessWidget {
  final UserRepository _userRepository = UserRepository();
  final UserModel user;

  ProfileEditMainPage({Key key, this.user}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        iconTheme: IconThemeData(
          color: WagsColor.PrimaryColor,
        ),
        centerTitle: true,
        backgroundColor: Colors.white,
        title: new Text(
          "Modifica profilo",
          style: new TextStyle(
            color: WagsColor.PrimaryColor,
          ),
        ),
      ),
      body: GestureDetector(
        onTap: () {
          FocusScope.of(context).requestFocus(new FocusNode());
        },
        child: Container(
          child: MultiBlocProvider(
            providers: [
              BlocProvider<ProfileBloc>(
                create: (context) =>
                    ProfileBloc(userRepository: _userRepository)
                      ..add(UninitializedProfile()),
              ),
              BlocProvider<ProfileEditBloc>(
                create: (context) =>
                    ProfileEditBloc(userRepository: _userRepository),
              ),
            ],
            child: ProfileEdit(
              user: user,
            ),
          ),
        ),
      ),
    );
  }
}

class ProfileEdit extends StatefulWidget {
  final UserModel user;

  const ProfileEdit({Key key, this.user}) : super(key: key);

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

class _ProfileEditState extends State<ProfileEdit> {
  final TextEditingController _nameController = TextEditingController();
  final TextEditingController _surnameController = TextEditingController();
  final TextEditingController _birthdayController = TextEditingController();
  final TextEditingController _genderController = TextEditingController();
  final TextEditingController _cityController = TextEditingController();
  final TextEditingController _nationController = TextEditingController();
  var profileImage = "";
  var initialItem = 0;

  ProfileEditBloc _profileEditBloc;
  ProfileBloc _profileBloc;

  bool get isPopulated =>
      _nameController.text.isNotEmpty &&
      _surnameController.text.isNotEmpty &&
      _birthdayController.text.isNotEmpty &&
      _genderController.text.isNotEmpty;

  bool isEditButtonEnabled(ProfileEditState state) {
    return state.isFormValid && isPopulated && !state.isSubmitting;
  }

  @override
  void initState() {
    super.initState();
    _profileEditBloc = BlocProvider.of<ProfileEditBloc>(context);
    _profileBloc = ProfileBloc(userRepository: UserRepository());

    _nameController.addListener(_onNameChanged);
    _surnameController.addListener(_onSurnameChanged);
    _birthdayController.addListener(_onBirthdayChanged);
    _genderController.addListener(_onGenderChanged);
    _cityController.addListener(_onCityChanged);
    _nationController.addListener(_onNationalityChanged);

    _nameController.text = widget.user.name != null ? widget.user.name : "";
    _surnameController.text =
        widget.user.surname != null ? widget.user.surname : "";
    _birthdayController.text =
        widget.user.birthday != null ? widget.user.birthday : "";
    _genderController.text =
        widget.user.gender != null ? widget.user.gender : "";
    _cityController.text = widget.user.city != null ? widget.user.city : "";
    _nationController.text =
        widget.user.nationality != null ? widget.user.nationality : "";

    if (widget.user.gender == "Donna") {
      initialItem = 2;
    } else if (widget.user.gender == "Uomo") {
      initialItem = 1;
    }

    KeyboardVisibilityNotification().addNewListener(
      onChange: (bool visible) {
        print('keyboard $visible');
      },
    );
  }

  @override
  void dispose() {
    _nameController.dispose();
    _surnameController.dispose();
    _birthdayController.dispose();
    _genderController.dispose();
    _cityController.dispose();
    _nationController.dispose();
    super.dispose();
  }

  void _onNameChanged() {
    _profileEditBloc.add(
      NameChanged(name: _nameController.text),
    );
  }

  void _onSurnameChanged() {
    _profileEditBloc.add(
      SurnameChanged(surname: _surnameController.text),
    );
  }

  void _onBirthdayChanged() {
    _profileEditBloc.add(
      BirthdayChanged(birthday: _birthdayController.text),
    );
  }

  void _onGenderChanged() {
    _profileEditBloc.add(
      GenderChanged(gender: _genderController.text),
    );
  }

  void _onCityChanged() {
    _profileEditBloc.add(
      CityChanged(city: _cityController.text),
    );
  }

  void _onNationalityChanged() {
    _profileEditBloc.add(
      NationalityChanged(nationality: _nationController.text),
    );
  }

  void _onFormSubmitted() {
    _profileEditBloc.add(
      Submitted(
        name: _nameController.text,
        surname: _surnameController.text,
        birthday: _birthdayController.text,
        gender: _genderController.text,
        city: _cityController.text,
        nationality: _nationController.text,
      ),
    );
  }

  Future<void> _optionsDialogBox() {
    return showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          content: new SingleChildScrollView(
            child: new ListBody(
              children: <Widget>[
                GestureDetector(
                  child: new Text('Take a picture'),
                  onTap: openCamera,
                ),
                Padding(
                  padding: EdgeInsets.all(8.0),
                ),
                GestureDetector(
                  child: new Text('Select from gallery'),
                  onTap: openGallery,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  Future<void> openCamera() async {
    var picture = await ImagePicker.pickImage(
      imageQuality: 40,
      source: ImageSource.camera,
    );
    Navigator.of(context, rootNavigator: true).pop('dialog');
    setState(() {
      this.profileImage = picture.path;
    });
    print(picture);
  }

  Future<void> openGallery() async {
    var gallery = await ImagePicker.pickImage(
      imageQuality: 40,
      source: ImageSource.gallery,
    );
    Navigator.of(context, rootNavigator: true).pop('dialog');
    setState(() {
      this.profileImage = gallery.path;
    });
    print(gallery);
  }

  void _showBottom() {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext builder) {
        return Scaffold(
          appBar: AppBar(
            title: Text(
              "Seleziona il Sesso",
              textAlign: TextAlign.justify,
              style: new TextStyle(
                fontFamily: "AvenirNext",
                fontSize: 18,
                color: Colors.black,
                fontWeight: FontWeight.w400,
              ),
            ),
            backgroundColor: Colors.white,
          ),
          body: Container(
            child: CupertinoPicker(
              scrollController:
                  FixedExtentScrollController(initialItem: initialItem),
              magnification: 1.0,
              backgroundColor: Colors.white,
              children: <Widget>[
                Container(
                  padding: EdgeInsets.only(top: 8),
                  child: Text(
                    "",
                    style: new TextStyle(
                      fontFamily: "AvenirNext",
                      fontSize: 20,
                      color: Colors.black,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(top: 8),
                  child: Text(
                    "Uomo",
                    style: new TextStyle(
                      fontFamily: "AvenirNext",
                      fontSize: 20,
                      color: Colors.black,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(top: 8),
                  child: Text(
                    "Donna",
                    style: new TextStyle(
                      fontFamily: "AvenirNext",
                      fontSize: 20,
                      color: Colors.black,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                ),
              ],
              itemExtent: 40, //height of each item
              looping: false,
              onSelectedItemChanged: (int index) {
                if (index == 0) {
                  _genderController.text = "";
                  setState(() {
                    initialItem = 0;
                  });
                } else if (index == 1) {
                  _genderController.text = "Uomo";
                  setState(() {
                    initialItem = 1;
                  });
                } else {
                  _genderController.text = "Donna";
                  setState(() {
                    initialItem = 2;
                  });
                }
              },
            ),
          ),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return BlocListener<ProfileEditBloc, ProfileEditState>(
      listener: (context, state) {
        if (state.isSubmitting) {
          Scaffold.of(context)
            ..hideCurrentSnackBar()
            ..showSnackBar(
              SnackBar(
                content: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      'Salvataggio in corso...',
                      style: new TextStyle(
                        fontFamily: "AvenirNext",
                        fontSize: 15,
                        color: Colors.white,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                    CircularProgressIndicator(),
                  ],
                ),
              ),
            );
        }
        if (state.isSuccess) {
          BlocProvider.of<ProfileBloc>(context).add(UninitializedProfile());
          Navigator.of(context).pop();
        }
        if (state.isFailure) {
          Scaffold.of(context)
            ..hideCurrentSnackBar()
            ..showSnackBar(
              SnackBar(
                content: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      'Aggiornamento fallita...',
                      style: new TextStyle(
                        fontFamily: "AvenirNext",
                        fontSize: 15,
                        color: Colors.black,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                    Icon(Icons.error),
                  ],
                ),
                backgroundColor: Colors.red,
              ),
            );
        }
      },
      child: BlocBuilder<ProfileEditBloc, ProfileEditState>(
        builder: (context, state) {
          return SingleChildScrollView(
            padding: EdgeInsets.only(left: 30, right: 30, top: 30, bottom: 90),
            child: Form(
              child: Container(
                child: Column(
                  children: <Widget>[
                    Column(
                      children: <Widget>[
                        IconButton(
                          icon: Icon(Icons.exit_to_app),
                          onPressed: () {
                            BlocProvider.of<AuthenticationBloc>(context).add(
                              LoggedOut(),
                            );
                          },
                        ),
                        Row(
                          children: <Widget>[
                            widget.user.image == ""
                                ? InkWell(
                                    onTap: _optionsDialogBox,
                                    child: ClipRRect(
                                      borderRadius: BorderRadius.circular(45.0),
                                      child: Image(
                                        width: 90,
                                        height: 90,
                                        image: AssetImage(
                                          this.profileImage == ""
                                              ? "assets/profilo_placeholder.png"
                                              : this.profileImage,
                                        ),
                                        fit: BoxFit.cover,
                                      ),
                                    ),
                                  )
                                : InkWell(
                                    onTap: _optionsDialogBox,
                                    child: ClipRRect(
                                      borderRadius: BorderRadius.circular(45.0),
                                      child: FadeInImage.memoryNetwork(
                                        fit: BoxFit.cover,
                                        width: 90,
                                        height: 90,
                                        placeholder: kTransparentImage,
                                        image:
                                            'https://projectinvictus.azurewebsites.net/userImage/${widget.user.uid}/${widget.user.image}',
                                      ),
                                    ),
                                  ),
                            SizedBox(
                              width: 10,
                            ),
                            InkWell(
                              onTap: _optionsDialogBox,
                              child: Text(
                                "Aggiungi immagine",
                                style: TextStyle(
                                  fontFamily: "AvenirNext",
                                  fontSize: 13,
                                  fontWeight: FontWeight.w400,
                                  color: WagsColor.PrimaryColor,
                                ),
                              ),
                            )
                          ],
                        ),
                        SizedBox(
                          height: 20,
                        ),
                        Row(
                          children: <Widget>[
                            SizedBox(width: 10),
                            Text(
                              "Nome",
                              style: TextStyle(
                                fontFamily: "AvenirNext",
                                fontSize: 12,
                                fontWeight: FontWeight.w400,
                                color: Colors.black45,
                              ),
                            ),
                          ],
                        ),
                        SizedBox(height: 5),
                        TextFormField(
                          controller: _nameController,
                          decoration: new InputDecoration(
                            hintText: "",
                            fillColor: Colors.red,
                            border: new OutlineInputBorder(
                              borderRadius: new BorderRadius.circular(8.0),
                              borderSide: new BorderSide(),
                            ),
                          ),
                          keyboardType: TextInputType.emailAddress,
                          autocorrect: false,
                          autovalidate: true,
                          validator: (_) {
                            return !state.isNameValid
                                ? 'Nome non valido'
                                : null;
                          },
                        ),
                      ],
                    ),
                    SizedBox(height: 20),
                    Column(
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            SizedBox(width: 10),
                            Text(
                              "Cognome",
                              style: TextStyle(
                                fontFamily: "AvenirNext",
                                fontSize: 12,
                                fontWeight: FontWeight.w400,
                                color: Colors.black45,
                              ),
                            ),
                          ],
                        ),
                        SizedBox(height: 5),
                        TextFormField(
                          controller: _surnameController,
                          decoration: new InputDecoration(
                            hintText: "",
                            fillColor: Colors.red,
                            border: new OutlineInputBorder(
                              borderRadius: new BorderRadius.circular(8.0),
                              borderSide: new BorderSide(),
                            ),
                          ),
                          autocorrect: false,
                          autovalidate: true,
                          validator: (_) {
                            return !state.isSurnameValid
                                ? 'Cognome non valido'
                                : null;
                          },
                        ),
                      ],
                    ),
                    SizedBox(height: 20),
                    Column(
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            SizedBox(width: 10),
                            Text(
                              "Data di Nascita",
                              style: TextStyle(
                                fontFamily: "AvenirNext",
                                fontSize: 12,
                                fontWeight: FontWeight.w400,
                                color: Colors.black45,
                              ),
                            ),
                          ],
                        ),
                        SizedBox(height: 5),
                        TextFormField(
                          onTap: () {
                            DatePicker.showDatePicker(context,
                                showTitleActions: true,
                                minTime: DateTime(2018, 3, 5),
                                maxTime: DateTime(2019, 6, 7),
                                theme: DatePickerTheme(
                                  headerColor: Colors.white,
                                  backgroundColor: Colors.white,
                                  itemStyle: TextStyle(
                                    fontFamily: "AvenirNext",
                                    color: Colors.black,
                                    fontWeight: FontWeight.w400,
                                    fontSize: 18,
                                  ),
                                  doneStyle: TextStyle(
                                    fontFamily: "AvenirNext",
                                    color: Colors.black,
                                    fontSize: 16,
                                  ),
                                ),
                                onChanged: (date) {}, onConfirm: (date) {
                              final df = new DateFormat('dd/MM/yyyy');
                              _birthdayController.text = df.format(date);
                              print('confirm $date');
                            },
                                currentTime: DateTime.now(),
                                locale: LocaleType.it);
                          },
                          controller: _birthdayController,
                          decoration: new InputDecoration(
                            hintText: "",
                            fillColor: Colors.red,
                            border: new OutlineInputBorder(
                              borderRadius: new BorderRadius.circular(8.0),
                              borderSide: new BorderSide(),
                            ),
                          ),
                          readOnly: true,
                          autocorrect: false,
                          autovalidate: true,
                          validator: (_) {
                            return !state.isBirthdayValid
                                ? 'Data non valida'
                                : null;
                          },
                        ),
                      ],
                    ),
                    SizedBox(height: 20),
                    Column(
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            SizedBox(width: 10),
                            Text(
                              "Sesso",
                              style: TextStyle(
                                fontSize: 12,
                                fontWeight: FontWeight.w400,
                                color: Colors.black45,
                              ),
                            ),
                          ],
                        ),
                        SizedBox(height: 5),
                        TextFormField(
                          onTap: _showBottom,
                          controller: _genderController,
                          decoration: new InputDecoration(
                            hintText: "",
                            fillColor: Colors.red,
                            border: new OutlineInputBorder(
                              borderRadius: new BorderRadius.circular(8.0),
                              borderSide: new BorderSide(),
                            ),
                          ),
                          readOnly: true,
                          autocorrect: false,
                          autovalidate: true,
                          validator: (_) {
                            return !state.isGenderValid
                                ? 'Sesso non valido'
                                : null;
                          },
                        ),
                      ],
                    ),
                    SizedBox(height: 20),
                    Column(
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            SizedBox(width: 10),
                            Text(
                              "Città",
                              style: TextStyle(
                                fontSize: 12,
                                fontWeight: FontWeight.w400,
                                color: Colors.black45,
                              ),
                            ),
                          ],
                        ),
                        SizedBox(height: 5),
                        TextFormField(
                          controller: _cityController,
                          decoration: new InputDecoration(
                            hintText: "",
                            fillColor: Colors.red,
                            border: new OutlineInputBorder(
                              borderRadius: new BorderRadius.circular(8.0),
                              borderSide: new BorderSide(),
                            ),
                          ),
                          autocorrect: false,
                          autovalidate: true,
                        ),
                      ],
                    ),
                    SizedBox(height: 20),
                    Column(
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            SizedBox(width: 10),
                            Text(
                              "Nazione",
                              style: TextStyle(
                                fontSize: 12,
                                fontWeight: FontWeight.w400,
                                color: Colors.black45,
                              ),
                            ),
                          ],
                        ),
                        SizedBox(height: 5),
                        TextFormField(
                          controller: _nationController,
                          decoration: new InputDecoration(
                            hintText: "",
                            fillColor: Colors.red,
                            border: new OutlineInputBorder(
                              borderRadius: new BorderRadius.circular(8.0),
                              borderSide: new BorderSide(),
                            ),
                          ),
                          autocorrect: false,
                          autovalidate: true,
                        ),
                      ],
                    ),
                    Padding(
                      padding: EdgeInsets.symmetric(vertical: 30),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: <Widget>[
                          WagsButtonAzure(
                            onPressed: isEditButtonEnabled(state)
                                ? _onFormSubmitted
                                : null,
                            buttonText: "Salva",
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM