2022-10-31 17:15:05 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2022-08-26 15:31:42 +02:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
2022-09-21 11:09:24 +02:00
|
|
|
import 'package:example/utils/example_profile_service.dart';
|
2022-08-26 15:31:42 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-12-01 15:11:15 +01:00
|
|
|
|
2022-09-21 14:37:16 +02:00
|
|
|
import 'package:flutter_profile/flutter_profile.dart';
|
2022-08-26 15:31:42 +02:00
|
|
|
|
2022-09-21 11:09:24 +02:00
|
|
|
import 'utils/example_profile_data.dart';
|
|
|
|
|
2022-08-26 15:31:42 +02:00
|
|
|
void main() {
|
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
|
2022-09-21 11:09:24 +02:00
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({super.key});
|
2022-08-26 15:31:42 +02:00
|
|
|
|
|
|
|
@override
|
2022-09-21 11:09:24 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return const MaterialApp(
|
|
|
|
home: ProfileExample(),
|
|
|
|
);
|
|
|
|
}
|
2022-08-26 15:31:42 +02:00
|
|
|
}
|
|
|
|
|
2022-09-21 11:09:24 +02:00
|
|
|
class ProfileExample extends StatefulWidget {
|
|
|
|
const ProfileExample({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<ProfileExample> createState() => _ProfileExampleState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ProfileExampleState extends State<ProfileExample> {
|
2022-08-26 15:31:42 +02:00
|
|
|
late User _user;
|
2022-12-02 10:40:16 +01:00
|
|
|
ProfileData profileData = ExampleProfileData().fromMap(
|
|
|
|
{'email': 'example@email.com', 'about': 'about', 'remarks': 'remarks'});
|
2022-08-26 15:31:42 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_user = User(
|
2022-10-21 10:42:32 +02:00
|
|
|
firstName: 'Firstname',
|
|
|
|
lastName: 'Lastname',
|
|
|
|
image: Uint8List.fromList(
|
2022-08-26 15:31:42 +02:00
|
|
|
[],
|
|
|
|
),
|
2022-10-21 10:42:32 +02:00
|
|
|
profileData: profileData,
|
2022-08-26 15:31:42 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-12-02 10:40:16 +01:00
|
|
|
//get width and height
|
|
|
|
var width = MediaQuery.of(context).size.width;
|
|
|
|
|
2022-09-21 11:09:24 +02:00
|
|
|
return Scaffold(
|
2022-12-01 15:11:15 +01:00
|
|
|
body: Center(
|
2022-12-02 10:40:16 +01:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 400,
|
|
|
|
width: 800,
|
|
|
|
child: ProfilePage(
|
|
|
|
showItems: false,
|
|
|
|
prioritizedItems: const ['remarks', 'about'],
|
|
|
|
wrapViewOptions: WrapViewOptions(
|
|
|
|
direction: Axis.horizontal,
|
|
|
|
spacing: 16,
|
|
|
|
),
|
|
|
|
bottomActionText: 'Log out',
|
|
|
|
itemBuilderOptions: ItemBuilderOptions(
|
|
|
|
//no label for email
|
|
|
|
validators: {
|
|
|
|
'first_name': (String? value) {
|
|
|
|
if (value == null || value.isEmpty) {
|
|
|
|
return 'Field empty';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
'last_name': (String? value) {
|
|
|
|
if (value == null || value.isEmpty) {
|
|
|
|
return 'Field empty';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
'email': (String? value) {
|
|
|
|
if (value == null || value.isEmpty) {
|
|
|
|
return 'Field empty';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
user: _user,
|
|
|
|
service: ExampleProfileService(),
|
|
|
|
style: ProfileStyle(
|
|
|
|
avatarTextStyle: const TextStyle(fontSize: 20),
|
|
|
|
pagePadding: EdgeInsets.only(
|
|
|
|
top: 50,
|
|
|
|
bottom: 50,
|
|
|
|
left: width * 0.1,
|
|
|
|
right: width * 0.1,
|
|
|
|
),
|
|
|
|
),
|
2022-12-01 15:11:15 +01:00
|
|
|
),
|
|
|
|
),
|
2022-12-02 10:40:16 +01:00
|
|
|
const Text('test')
|
|
|
|
],
|
2022-08-26 16:28:40 +02:00
|
|
|
),
|
2022-08-26 15:31:42 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 15:11:15 +01:00
|
|
|
|
|
|
|
class CustomItemBuilderExample extends ItemBuilder {
|
|
|
|
CustomItemBuilderExample({
|
|
|
|
required super.options,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(String key, dynamic value, Widget? widget,
|
|
|
|
Function(String) updateItem, Function(String?) saveItem) {
|
|
|
|
if (widget == null) {
|
|
|
|
var controller = TextEditingController(
|
|
|
|
text: '${value ?? ''}',
|
|
|
|
);
|
|
|
|
|
|
|
|
late InputDecoration inputDecoration;
|
|
|
|
|
|
|
|
inputDecoration =
|
|
|
|
options.inputDecorationField?[key] ?? options.inputDecoration;
|
|
|
|
var formFieldKey = GlobalKey<FormFieldState>();
|
|
|
|
return SizedBox(
|
2022-12-02 10:40:16 +01:00
|
|
|
width: 400,
|
2022-12-01 15:11:15 +01:00
|
|
|
child: TextFormField(
|
|
|
|
keyboardType: options.keyboardType?[key],
|
|
|
|
key: formFieldKey,
|
|
|
|
controller: controller,
|
|
|
|
decoration: inputDecoration,
|
|
|
|
readOnly: options.readOnly,
|
|
|
|
onFieldSubmitted: (value) {
|
|
|
|
updateItem(value);
|
|
|
|
},
|
|
|
|
onSaved: (newValue) {
|
|
|
|
saveItem(newValue);
|
|
|
|
},
|
|
|
|
validator: (value) {
|
|
|
|
return options.validators?[key]?.call(value);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
}
|