import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:profile/profile.dart'; /// User is used to contain all user data. It consists of three standard fields: firstName, lastName and image. /// /// For additional data profileData can be used. class User { String? firstName; String? lastName; Uint8List? image; T? profileData; User( this.firstName, this.lastName, this.image, this.profileData, ); factory User.fromMap(Map data) { return User( data['firstName'], data['lastName'], data['image'], data['profileData'], ); } Map toMap() { return { 'firstName': firstName, 'lastName': lastName, 'image': image, 'profileData': profileData, }; } } /// ProfileData is used to store custom/addintional data for a user. /// /// The MapWidget method is used to bind a [Widget] to one of the keys. This will override the standard textfield. /// /// The Builditems method is used to make the list of field to house the user data. abstract class ProfileData { const ProfileData(); ProfileData fromMap(Map data); Map toMap(); Map mapWidget(VoidCallback update, BuildContext context); ProfileData create(); List buildItems( Map items, Map typeMap, double spacing, Function(String, String) updateProfile, { ItemBuilder? itemBuilder, ItemBuilderOptions? itemBuilderOptions, }) { var widgets = []; ItemBuilder builder = ItemBuilder( options: itemBuilderOptions ?? ItemBuilderOptions(), ); for (var item in items.entries) { itemBuilder == null ? widgets.add( builder.build( item.key, item.value, typeMap[item.key], (value) { updateProfile(item.key, value); }, ), ) : widgets.add( itemBuilder.build( item.key, item.value, typeMap[item.key], (value) { updateProfile(item.key, value); }, ), ); widgets.add(SizedBox( height: spacing, )); } return widgets; } }