cwtch-ui/lib/widgets/profilerow.dart

137 lines
6.0 KiB
Dart
Raw Permalink Normal View History

import 'package:cwtch/models/appstate.dart';
import 'package:cwtch/models/contactlist.dart';
import 'package:cwtch/models/profile.dart';
2021-06-24 23:10:45 +00:00
import 'package:flutter/material.dart';
import 'package:cwtch/views/addeditprofileview.dart';
import 'package:cwtch/views/contactsview.dart';
import 'package:cwtch/views/doublecolview.dart';
import 'package:cwtch/widgets/profileimage.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import '../main.dart';
import '../settings.dart';
class ProfileRow extends StatefulWidget {
@override
_ProfileRowState createState() => _ProfileRowState();
}
class _ProfileRowState extends State<ProfileRow> {
@override
Widget build(BuildContext context) {
var profile = Provider.of<ProfileInfoState>(context);
return Card(
clipBehavior: Clip.antiAlias,
2024-03-20 19:34:26 +00:00
color: Colors.transparent,
margin: EdgeInsets.all(0.0),
2021-06-24 23:10:45 +00:00
child: InkWell(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(6.0), //border size
2021-06-24 23:10:45 +00:00
child: ProfileImage(
badgeCount: profile.unreadMessages,
badgeColor: Provider.of<Settings>(context).theme.portraitProfileBadgeColor,
badgeTextColor: Provider.of<Settings>(context).theme.portraitProfileBadgeTextColor,
disabled: !profile.enabled,
2021-06-24 23:10:45 +00:00
diameter: 64.0,
imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment) ? profile.imagePath : profile.defaultImagePath,
border: profile.isOnline ? Provider.of<Settings>(context).theme.portraitOnlineBorderColor : Provider.of<Settings>(context).theme.portraitOfflineBorderColor)),
2021-06-24 23:10:45 +00:00
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
2021-06-30 20:59:52 +00:00
children: [
Container(
2024-03-20 19:34:26 +00:00
height: 18.0 * Provider.of<Settings>(context).fontScaling + 18.0,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(),
padding: EdgeInsets.all(5.0),
child: Text(
profile.nickname,
semanticsLabel: profile.nickname,
2023-05-15 19:05:28 +00:00
style: TextStyle(fontFamily: "Inter", fontSize: 18.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
softWrap: true,
overflow: TextOverflow.ellipsis,
)),
2021-09-14 16:05:07 +00:00
Visibility(
visible: !Provider.of<Settings>(context).streamerMode,
2021-09-14 16:05:07 +00:00
child: ExcludeSemantics(
child: Text(
profile.onion,
softWrap: true,
style: TextStyle(
fontFamily: "RobotoMono",
fontSize: 14.0 * Provider.of<Settings>(context).fontScaling,
color: ((Provider.of<Settings>(context).theme.mainTextColor) as Color).withOpacity(0.8)),
overflow: TextOverflow.ellipsis,
)))
2021-06-30 20:59:52 +00:00
],
)),
2021-06-24 23:10:45 +00:00
IconButton(
enableFeedback: true,
splashRadius: Material.defaultSplashRadius / 2,
2021-06-24 23:10:45 +00:00
tooltip: AppLocalizations.of(context)!.editProfile + " " + profile.nickname,
icon: Icon(Icons.create, color: Provider.of<Settings>(context).current().mainTextColor),
2021-06-24 23:10:45 +00:00
onPressed: () {
2021-10-29 23:37:02 +00:00
_pushEditProfile(onion: profile.onion, displayName: profile.nickname, profileImage: profile.imagePath, encrypted: profile.isEncrypted);
2021-06-24 23:10:45 +00:00
},
)
],
),
onTap: () {
setState(() {
var appState = Provider.of<AppState>(context, listen: false);
appState.selectedProfile = profile.onion;
appState.selectedConversation = null;
2021-06-30 20:59:52 +00:00
_pushContactList(profile, appState.isLandscape(context)); //orientation == Orientation.landscape);
2021-06-24 23:10:45 +00:00
});
},
));
}
void _pushContactList(ProfileInfoState profile, bool isLandscape) {
Navigator.of(context).push(
PageRouteBuilder(
2021-06-24 23:10:45 +00:00
settings: RouteSettings(name: "conversations"),
pageBuilder: (c, a1, a2) {
2021-06-30 20:59:52 +00:00
return OrientationBuilder(builder: (orientationBuilderContext, orientation) {
return MultiProvider(
providers: [ChangeNotifierProvider<ProfileInfoState>.value(value: profile), ChangeNotifierProvider<ContactListState>.value(value: profile.contactList)],
2021-06-30 20:59:52 +00:00
builder: (innercontext, widget) {
var appState = Provider.of<AppState>(context);
var settings = Provider.of<Settings>(context);
return settings.uiColumns(appState.isLandscape(innercontext)).length > 1 ? DoubleColumnView() : ContactsView();
});
2021-06-24 23:10:45 +00:00
});
},
transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
transitionDuration: Duration(milliseconds: 200),
2021-06-24 23:10:45 +00:00
),
);
}
2024-02-14 04:02:33 +00:00
void _pushEditProfile({onion = "", displayName = "", profileImage = "", encrypted = true}) {
Navigator.of(context).push(
PageRouteBuilder(
pageBuilder: (bcontext, a1, a2) {
var profile = Provider.of<FlwtchState>(bcontext).profs.getProfile(onion)!;
return MultiProvider(
providers: [
ChangeNotifierProvider<ProfileInfoState>.value(
value: profile,
),
],
builder: (context, widget) => AddEditProfileView(),
);
},
transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
transitionDuration: Duration(milliseconds: 200),
),
);
2021-06-24 23:10:45 +00:00
}
}