forked from firka/student-legacy
added double tap account change support
This commit is contained in:
parent
be1265fc87
commit
08faa694f2
@ -1,4 +1,15 @@
|
|||||||
|
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||||
import 'package:filcnaplo/models/settings.dart';
|
import 'package:filcnaplo/models/settings.dart';
|
||||||
|
import 'package:filcnaplo/models/user.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/client/client.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/absence_provider.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/event_provider.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/exam_provider.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/homework_provider.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/message_provider.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/note_provider.dart';
|
||||||
|
import 'package:filcnaplo_kreta_api/providers/timetable_provider.dart';
|
||||||
import 'package:filcnaplo_mobile_ui/common/profile_image/profile_image.dart';
|
import 'package:filcnaplo_mobile_ui/common/profile_image/profile_image.dart';
|
||||||
import 'package:filcnaplo_mobile_ui/screens/settings/settings_screen.dart';
|
import 'package:filcnaplo_mobile_ui/screens/settings/settings_screen.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -15,6 +26,28 @@ class ProfileButton extends StatelessWidget {
|
|||||||
final bool pMode =
|
final bool pMode =
|
||||||
Provider.of<SettingsProvider>(context, listen: false).presentationMode;
|
Provider.of<SettingsProvider>(context, listen: false).presentationMode;
|
||||||
|
|
||||||
|
late UserProvider user;
|
||||||
|
late User? account;
|
||||||
|
|
||||||
|
Future<void> restore() => Future.wait([
|
||||||
|
Provider.of<GradeProvider>(context, listen: false).restore(),
|
||||||
|
Provider.of<TimetableProvider>(context, listen: false).restoreUser(),
|
||||||
|
Provider.of<ExamProvider>(context, listen: false).restore(),
|
||||||
|
Provider.of<HomeworkProvider>(context, listen: false).restore(),
|
||||||
|
Provider.of<MessageProvider>(context, listen: false).restore(),
|
||||||
|
Provider.of<NoteProvider>(context, listen: false).restore(),
|
||||||
|
Provider.of<EventProvider>(context, listen: false).restore(),
|
||||||
|
Provider.of<AbsenceProvider>(context, listen: false).restore(),
|
||||||
|
Provider.of<KretaClient>(context, listen: false).refreshLogin(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
user = Provider.of<UserProvider>(context);
|
||||||
|
try {
|
||||||
|
account = user.getUsers()[1];
|
||||||
|
} catch (err) {
|
||||||
|
account = null;
|
||||||
|
}
|
||||||
|
|
||||||
return ProfileImage(
|
return ProfileImage(
|
||||||
backgroundColor: !pMode
|
backgroundColor: !pMode
|
||||||
? child.backgroundColor
|
? child.backgroundColor
|
||||||
@ -48,6 +81,12 @@ class ProfileButton extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
onDoubleTap: () {
|
||||||
|
if (account != null) {
|
||||||
|
user.setUser(account.id);
|
||||||
|
restore().then((_) => user.setUser(account!.id));
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ class ProfileImage extends StatefulWidget {
|
|||||||
const ProfileImage({
|
const ProfileImage({
|
||||||
Key? key,
|
Key? key,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
|
this.onDoubleTap,
|
||||||
|
this.onLongPress,
|
||||||
this.name,
|
this.name,
|
||||||
this.backgroundColor,
|
this.backgroundColor,
|
||||||
this.radius = 20.0,
|
this.radius = 20.0,
|
||||||
@ -21,6 +23,8 @@ class ProfileImage extends StatefulWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final void Function()? onTap;
|
final void Function()? onTap;
|
||||||
|
final void Function()? onDoubleTap;
|
||||||
|
final void Function()? onLongPress;
|
||||||
final String? name;
|
final String? name;
|
||||||
final Color? backgroundColor;
|
final Color? backgroundColor;
|
||||||
final double radius;
|
final double radius;
|
||||||
@ -46,7 +50,10 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
|
|
||||||
void updatePic() {
|
void updatePic() {
|
||||||
profilePicture = widget.profilePictureString != ""
|
profilePicture = widget.profilePictureString != ""
|
||||||
? Image.memory(const Base64Decoder().convert(widget.profilePictureString), fit: BoxFit.scaleDown, gaplessPlayback: true)
|
? Image.memory(
|
||||||
|
const Base64Decoder().convert(widget.profilePictureString),
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
gaplessPlayback: true)
|
||||||
: null;
|
: null;
|
||||||
profPicSaved = widget.profilePictureString;
|
profPicSaved = widget.profilePictureString;
|
||||||
}
|
}
|
||||||
@ -63,7 +70,8 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildWithoutHero(BuildContext context) {
|
Widget buildWithoutHero(BuildContext context) {
|
||||||
Color color = ColorUtils.foregroundColor(widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor);
|
Color color = ColorUtils.foregroundColor(
|
||||||
|
widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor);
|
||||||
Color roleColor;
|
Color roleColor;
|
||||||
|
|
||||||
if (Theme.of(context).brightness == Brightness.light) {
|
if (Theme.of(context).brightness == Brightness.light) {
|
||||||
@ -78,9 +86,12 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
Material(
|
Material(
|
||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
shape: const CircleBorder(),
|
shape: const CircleBorder(),
|
||||||
color: widget.backgroundColor ?? AppColors.of(context).text.withOpacity(.15),
|
color: widget.backgroundColor ??
|
||||||
|
AppColors.of(context).text.withOpacity(.15),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: widget.onTap,
|
onTap: widget.onTap,
|
||||||
|
onDoubleTap: widget.onDoubleTap,
|
||||||
|
onLongPress: widget.onLongPress,
|
||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
height: widget.radius * 2,
|
height: widget.radius * 2,
|
||||||
@ -88,7 +99,8 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
child: widget.name != null && (widget.name?.trim().length ?? 0) > 0
|
child:
|
||||||
|
widget.name != null && (widget.name?.trim().length ?? 0) > 0
|
||||||
? Center(
|
? Center(
|
||||||
child: widget.censored
|
child: widget.censored
|
||||||
? Container(
|
? Container(
|
||||||
@ -101,7 +113,9 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
)
|
)
|
||||||
: profilePicture ??
|
: profilePicture ??
|
||||||
Text(
|
Text(
|
||||||
(widget.name?.trim().length ?? 0) > 0 ? (widget.name ?? "?").trim()[0] : "?",
|
(widget.name?.trim().length ?? 0) > 0
|
||||||
|
? (widget.name ?? "?").trim()[0]
|
||||||
|
: "?",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: color,
|
color: color,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
@ -121,7 +135,8 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
width: widget.radius * 2,
|
width: widget.radius * 2,
|
||||||
child: Container(
|
child: Container(
|
||||||
alignment: Alignment.bottomRight,
|
alignment: Alignment.bottomRight,
|
||||||
child: Icon(Icons.shield, color: roleColor, size: widget.radius / 1.3),
|
child: Icon(Icons.shield,
|
||||||
|
color: roleColor, size: widget.radius / 1.3),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -129,7 +144,8 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildWithHero(BuildContext context) {
|
Widget buildWithHero(BuildContext context) {
|
||||||
Color color = ColorUtils.foregroundColor(widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor);
|
Color color = ColorUtils.foregroundColor(
|
||||||
|
widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor);
|
||||||
Color roleColor;
|
Color roleColor;
|
||||||
|
|
||||||
if (Theme.of(context).brightness == Brightness.light) {
|
if (Theme.of(context).brightness == Brightness.light) {
|
||||||
@ -141,7 +157,9 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
Widget child = FittedBox(
|
Widget child = FittedBox(
|
||||||
fit: BoxFit.fitHeight,
|
fit: BoxFit.fitHeight,
|
||||||
child: Text(
|
child: Text(
|
||||||
(widget.name?.trim().length ?? 0) > 0 ? (widget.name ?? "?").trim()[0] : "?",
|
(widget.name?.trim().length ?? 0) > 0
|
||||||
|
? (widget.name ?? "?").trim()[0]
|
||||||
|
: "?",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: color,
|
color: color,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
@ -163,7 +181,10 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
child: Material(
|
child: Material(
|
||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
shape: const CircleBorder(),
|
shape: const CircleBorder(),
|
||||||
color: profilePicture != null ? Colors.transparent : widget.backgroundColor ?? AppColors.of(context).text.withOpacity(.15),
|
color: profilePicture != null
|
||||||
|
? Colors.transparent
|
||||||
|
: widget.backgroundColor ??
|
||||||
|
AppColors.of(context).text.withOpacity(.15),
|
||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
height: widget.radius * 2,
|
height: widget.radius * 2,
|
||||||
@ -204,7 +225,8 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
width: widget.radius * 2,
|
width: widget.radius * 2,
|
||||||
child: Container(
|
child: Container(
|
||||||
alignment: Alignment.bottomRight,
|
alignment: Alignment.bottomRight,
|
||||||
child: Icon(Icons.shield, color: roleColor, size: widget.radius / 1.3),
|
child: Icon(Icons.shield,
|
||||||
|
color: roleColor, size: widget.radius / 1.3),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -216,6 +238,8 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||||||
shape: const CircleBorder(),
|
shape: const CircleBorder(),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: widget.onTap,
|
onTap: widget.onTap,
|
||||||
|
onDoubleTap: widget.onDoubleTap,
|
||||||
|
onLongPress: widget.onLongPress,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: widget.radius * 2,
|
height: widget.radius * 2,
|
||||||
width: widget.radius * 2,
|
width: widget.radius * 2,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:filcnaplo/models/user.dart';
|
import 'package:filcnaplo/models/user.dart';
|
||||||
import 'package:filcnaplo/utils/color.dart';
|
|
||||||
import 'package:filcnaplo_mobile_ui/common/bottom_card.dart';
|
import 'package:filcnaplo_mobile_ui/common/bottom_card.dart';
|
||||||
import 'package:filcnaplo_mobile_ui/common/detail.dart';
|
import 'package:filcnaplo_mobile_ui/common/detail.dart';
|
||||||
import 'package:filcnaplo_mobile_ui/common/profile_image/profile_image.dart';
|
import 'package:filcnaplo_mobile_ui/common/profile_image/profile_image.dart';
|
||||||
@ -13,7 +12,8 @@ class AccountView extends StatelessWidget {
|
|||||||
|
|
||||||
final User user;
|
final User user;
|
||||||
|
|
||||||
static void show(User user, {required BuildContext context}) => showBottomCard(context: context, child: AccountView(user));
|
static void show(User user, {required BuildContext context}) =>
|
||||||
|
showBottomCard(context: context, child: AccountView(user));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -28,7 +28,7 @@ class AccountView extends StatelessWidget {
|
|||||||
AccountTile(
|
AccountTile(
|
||||||
profileImage: ProfileImage(
|
profileImage: ProfileImage(
|
||||||
name: _firstName,
|
name: _firstName,
|
||||||
backgroundColor: ColorUtils.stringToColor(user.name),
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
role: user.role,
|
role: user.role,
|
||||||
),
|
),
|
||||||
name: SelectableText(
|
name: SelectableText(
|
||||||
@ -41,12 +41,19 @@ class AccountView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
|
|
||||||
// User details
|
// User details
|
||||||
Detail(title: "birthdate".i18n, description: DateFormat("yyyy. MM. dd.").format(user.student.birth)),
|
Detail(
|
||||||
|
title: "birthdate".i18n,
|
||||||
|
description:
|
||||||
|
DateFormat("yyyy. MM. dd.").format(user.student.birth)),
|
||||||
Detail(title: "school".i18n, description: user.student.school.name),
|
Detail(title: "school".i18n, description: user.student.school.name),
|
||||||
if (user.student.className != null) Detail(title: "class".i18n, description: user.student.className!),
|
if (user.student.className != null)
|
||||||
if (user.student.address != null) Detail(title: "address".i18n, description: user.student.address!),
|
Detail(title: "class".i18n, description: user.student.className!),
|
||||||
|
if (user.student.address != null)
|
||||||
|
Detail(title: "address".i18n, description: user.student.address!),
|
||||||
if (user.student.parents.isNotEmpty)
|
if (user.student.parents.isNotEmpty)
|
||||||
Detail(title: "parents".plural(user.student.parents.length), description: user.student.parents.join(", ")),
|
Detail(
|
||||||
|
title: "parents".plural(user.student.parents.length),
|
||||||
|
description: user.student.parents.join(", ")),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user