0

I would like to use sharedpreferences with Flutter in order create a user profile page in my flutter app.

It is going to be an onboarding session in order to save user name,marital status and birthday. If same user open the app it is going to pass onboarding session automatically and home screen of the app will open.

I do not want to use login process. When user opens the app the app will recognize the user automatically if the user is completed onboarding. There will be 3 seperate pages which asks the name , age and gender of the user. After user complete the onboarding the app will save the all the information profile page of the user. UI will be like the below video :) Here is the UI video

How can I realize this?

  • There is lot of stuff available on the internet related to this, Have you search for anything? – Jitesh Mohite May 25 '20 at 12:22
  • Yes I searched but I did not implement into my app! I'm quite new to programming and Flutter :) I need your support with a sample code. Thank you! –  May 25 '20 at 12:23
  • The sample code is already provided in https://pub.dev/packages/shared_preferences, If you want it with the context of your app, we need to see some effort from your side Sammy... – Sidak May 25 '20 at 13:41
  • I tried but I did not realize it sorry –  May 25 '20 at 13:52

1 Answers1

0

I created a sheet in order to save birtdate of the user with sharedpreferences but I did not achieve!

Could you please check some part of the codes below and explain me what is the mistake that I made. Thank you!

  bool isDateSelected = false;
  DateTime birthDate;
  DateTime _selectedDate;




 @override
 void initState() {
 _read1();
 super.initState();
 }

_read1() async {
prefs = await SharedPreferences.getInstance();
setState(() {
  prefs.getString('selectedDate');
});
}

void _pickDateDialog() {
showDatePicker(
        context: context,
        initialDate: DateTime.now(),
        firstDate: DateTime(1950),
        lastDate: DateTime.now())
    .then((pickedDate) {
  if (pickedDate == null) {
    return;
  }
  setState(() {
    prefs.setString('selectedDate', _selectedDate.toIso8601String());
  });
});
}  
    Padding(
              padding: const EdgeInsets.all(10.0),
            ),
            Text(
              'Select Your Birthdate',
              style: TextStyle(color: Colors.pink, fontSize: 20.0),
            ),
            GestureDetector(
                child: new Icon(
                  Icons.date_range,
                  color: Colors.pink,
                ),
                onTap: () {
                  _pickDateDialog();
                }),
            Padding(
              padding: const EdgeInsets.all(10.0),
            ),
            Text(
              _selectedDate == null
                  ? 'No date chosen!'
                  : '${DateFormat.yMMMd().format(_selectedDate)}',
              style: TextStyle(color: Colors.white),
            ),