flutter_profile/example/lib/main.dart

156 lines
3.4 KiB
Dart
Raw Normal View History

2022-08-26 15:31:42 +02:00
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:profile/profile.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late User _user;
2022-08-26 16:28:40 +02:00
MyProfileData profileData = MyProfileData();
2022-08-26 15:31:42 +02:00
@override
void initState() {
super.initState();
_user = User(
'firstName',
'lastName',
Uint8List.fromList(
[],
),
profileData,
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ProfilePage(
2022-08-26 16:28:40 +02:00
service: MyProfileService(),
2022-08-26 15:31:42 +02:00
user: _user,
),
);
}
}
2022-08-26 16:28:40 +02:00
class MyProfileService extends ProfileService {
@override
deleteProfile() {
return super.deleteProfile();
}
@override
editProfile<T extends ProfileData>(
User<ProfileData> user, String key, String value) {
return super.editProfile(user, key, value);
}
@override
uploadImage(context) {
return super.uploadImage(context);
2022-08-26 16:28:40 +02:00
}
}
2022-08-26 15:31:42 +02:00
class MyProfileData extends ProfileData {
2022-08-26 16:28:40 +02:00
MyProfileData({
2022-08-26 15:31:42 +02:00
this.justMyNumber = '1',
this.justMyString = 2,
});
final String justMyNumber;
2022-08-26 16:28:40 +02:00
int justMyString;
2022-08-26 15:31:42 +02:00
@override
Map<String, dynamic> mapWidget(Function update, BuildContext context) {
2022-08-26 15:31:42 +02:00
return {
'justMyString': SizedBox(
2022-08-26 15:31:42 +02:00
height: 100,
2022-08-26 16:28:40 +02:00
width: 300,
child: Row(
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: justMyString == 1 ? Colors.green : Colors.blue,
2022-08-26 16:28:40 +02:00
),
onPressed: () {
justMyString = 1;
update();
},
child: const Text('1'),
),
const Spacer(),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: justMyString == 2 ? Colors.green : Colors.blue,
2022-08-26 16:28:40 +02:00
),
onPressed: () {
justMyString = 2;
update();
},
child: const Text('2'),
),
const Spacer(),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: justMyString == 3 ? Colors.green : Colors.blue,
2022-08-26 16:28:40 +02:00
),
onPressed: () {
justMyString = 3;
update();
},
child: const Text('3'),
),
const Spacer(),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: justMyString == 4 ? Colors.green : Colors.blue,
2022-08-26 16:28:40 +02:00
),
onPressed: () {
justMyString = 4;
update();
},
child: const Text('4'),
),
],
),
2022-08-26 15:31:42 +02:00
),
2022-08-26 16:28:40 +02:00
'justMyNumber': null,
2022-08-26 15:31:42 +02:00
};
}
@override
ProfileData fromMap(Map<String, dynamic> data) {
return MyProfileData(
justMyNumber: data['justMyNumber'],
justMyString: int.parse(
data['justMyString'].toString(),
),
);
}
@override
Map<String, dynamic> toMap() {
return {
'justMyNumber': justMyNumber,
'justMyString': justMyString,
};
}
@override
ProfileData create() {
2022-08-26 16:28:40 +02:00
return MyProfileData();
2022-08-26 15:31:42 +02:00
}
}