From fe4a4c9f7568331ee36b7349f7e6771c54a9057b Mon Sep 17 00:00:00 2001 From: erinn Date: Wed, 10 Feb 2021 17:03:02 -0800 Subject: [PATCH] more contact wiring, adding contactrow, more bugfixes --- lib/model.dart | 6 ++++ lib/views/contactsview.dart | 45 +++------------------------ lib/views/profilemgrview.dart | 2 +- lib/widgets/contactrow.dart | 57 +++++++++++++++++++++++++++++++++++ lib/widgets/profilerow.dart | 26 ++++++++-------- 5 files changed, 80 insertions(+), 56 deletions(-) create mode 100644 lib/widgets/contactrow.dart diff --git a/lib/model.dart b/lib/model.dart index 87a9bc9..3ec229c 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -155,6 +155,12 @@ class ProfileInfoState extends ChangeNotifier { this._unreadMessages = newVal; notifyListeners(); } + + @override + void dispose() { + super.dispose(); + print("profileinfostate.dispose()"); + } } class ContactInfoState extends ChangeNotifier { diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 2ab5e34..f706ea3 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -1,11 +1,8 @@ -import 'dart:collection'; -import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:flutter_app/widgets/contactrow.dart'; import 'package:provider/provider.dart'; import '../main.dart'; -import '../opaque.dart'; import 'addcontactview.dart'; -import 'messageview.dart'; import '../model.dart'; class ContactsView extends StatefulWidget { @@ -61,30 +58,9 @@ class _ContactsViewState extends State { builder: (BuildContext context, AsyncSnapshot snapshot) { final tiles = Provider.of(context).onions.map( (ContactInfoState contact) { - return ListTile( - leading: SizedBox( - width: 60, - height: 60, - child: ClipOval( - child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage("assets/profiles/001-centaur.png"), width:50,height:50,))), - //child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage(contact.imagePath), width:50,height:50,))), - ), - ), - trailing: contact.isInvitation != null && contact.isInvitation ? Column(children:[Icon(Icons.favorite, color: Opaque.current().mainTextColor()),Icon(Icons.delete, color: Opaque.current().mainTextColor())]) : Text("99+"),//(nb: Icons.create is a pencil and we use it for "edit", not create) - title: Text( - contact.nickname, - style: Provider.of(context).biggerFont, - ), - subtitle: Text(contact.status), - onTap: () { - setState(() { - var flwtch = Provider.of(context, listen:false); - flwtch.setState(() => flwtch.selectedConversation = contact.onion); - - // case 2/3 handled by Double/TripleColumnView respectively - if (flwtch.columns.length == 1) _pushMessageView(contact.onion); - }); - }, + return ChangeNotifierProvider( + create: (context) => contact, + builder: (context, child) => ContactRow(), ); }, ); @@ -99,19 +75,6 @@ class _ContactsViewState extends State { ); } - void _pushMessageView(String handle) { - Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext builderContext) { - return MultiProvider( - providers: [ChangeNotifierProvider(create: (_) => Provider.of(context)),], - child: MessageView(conversationHandle: handle), - ); - }, - ), - ); - } - void _pushAddContact() { Navigator.of(context).push( MaterialPageRoute( diff --git a/lib/views/profilemgrview.dart b/lib/views/profilemgrview.dart index 0b85620..4a7ec63 100644 --- a/lib/views/profilemgrview.dart +++ b/lib/views/profilemgrview.dart @@ -107,7 +107,7 @@ class _ProfileMgrViewState extends State { (ProfileInfoState profile) { return ChangeNotifierProvider( create: (context) => profile, - builder: (context, child) => ProfileRow(profile), + builder: (context, child) => ProfileRow(), ); }, ); diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart new file mode 100644 index 0000000..29fe637 --- /dev/null +++ b/lib/widgets/contactrow.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_app/views/messageview.dart'; +import 'package:provider/provider.dart'; + +import '../main.dart'; +import '../model.dart'; +import '../opaque.dart'; + +class ContactRow extends StatefulWidget { + @override + _ContactRowState createState() => _ContactRowState(); +} + +class _ContactRowState extends State { + @override + Widget build(BuildContext context) { + var contact = Provider.of(context); + return ListTile( + leading: SizedBox( + width: 60, + height: 60, + child: ClipOval( + child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage("assets/profiles/001-centaur.png"), width:50,height:50,))), + //child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage(contact.imagePath), width:50,height:50,))), + ), + ), + trailing: contact.isInvitation != null && contact.isInvitation ? Column(children:[Icon(Icons.favorite, color: Opaque.current().mainTextColor()),Icon(Icons.delete, color: Opaque.current().mainTextColor())]) : Text("99+"),//(nb: Icons.create is a pencil and we use it for "edit", not create) + title: Text( + contact.nickname, + style: Provider.of(context).biggerFont, + ), + subtitle: Text(contact.status), + onTap: () { + setState(() { + var flwtch = Provider.of(context, listen:false); + flwtch.setState(() => flwtch.selectedConversation = contact.onion); + + // case 2/3 handled by Double/TripleColumnView respectively + if (flwtch.columns.length == 1) _pushMessageView(contact.onion); + }); + }, + ); + } + + void _pushMessageView(String handle) { + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext builderContext) { + return MultiProvider( + providers: [ChangeNotifierProvider(create: (_) => Provider.of(context)),], + child: MessageView(conversationHandle: handle), + ); + }, + ), + ); + } +} diff --git a/lib/widgets/profilerow.dart b/lib/widgets/profilerow.dart index 0bcd877..5e83ec8 100644 --- a/lib/widgets/profilerow.dart +++ b/lib/widgets/profilerow.dart @@ -9,9 +9,6 @@ import '../model.dart'; import '../opaque.dart'; class ProfileRow extends StatefulWidget { - final ProfileInfoState profile; - ProfileRow(this.profile); - @override _ProfileRowState createState() => _ProfileRowState(); } @@ -19,35 +16,36 @@ class ProfileRow extends StatefulWidget { class _ProfileRowState extends State { @override Widget build(BuildContext context) { + var profile = Provider.of(context); return ListTile( leading: SizedBox( width: 60, height: 60, child: ClipOval( - child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage("assets/" + widget.profile.imagePath), width:50,height:50,))), + child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage("assets/" + profile.imagePath), width:50,height:50,))), ), ) , trailing: IconButton( icon: Icon(Icons.create, color: Provider.of(context).current().mainTextColor()), - onPressed: () { _pushAddEditProfile(onion: widget.profile.onion); }, + onPressed: () { _pushAddEditProfile(onion: profile.onion); }, ),//(nb: Icons.create is a pencil and we use it for "edit", not create) title: Text( - widget.profile.nickname, + profile.nickname, style: Provider.of(context).biggerFont, ), - subtitle: Text(widget.profile.onion), + subtitle: Text(profile.onion), onTap: () { setState(() { var flwtch = Provider.of(context, listen:false); - flwtch.cwtch.SelectProfile(widget.profile.onion); + flwtch.cwtch.SelectProfile(profile.onion); flwtch.setState(() { - flwtch.selectedProfile = widget.profile; + flwtch.selectedProfile = profile; flwtch.selectedConversation = ""; }); switch (flwtch.columns.length) { - case 1: _pushContactList(widget.profile, false); break; - case 2: _pushContactList(widget.profile, true); break; + case 1: _pushContactList(profile, false); break; + case 2: _pushContactList(profile, true); break; } // case 3: handled by TripleColumnView }); }, @@ -57,11 +55,11 @@ class _ProfileRowState extends State { void _pushContactList(ProfileInfoState profile, bool includeDoublePane) { Navigator.of(context).push( MaterialPageRoute( - builder: (BuildContext context) { + builder: (BuildContext buildcontext) { return MultiProvider( providers: [ - ChangeNotifierProvider(create: (_) => profile), - ChangeNotifierProvider(create: (_) => ContactListState(Provider.of(context).cwtch, profile.onion),), + ChangeNotifierProvider.value(value: profile), + ChangeNotifierProvider(create: (_) => ContactListState(Provider.of(buildcontext).cwtch, profile.onion),), ], builder: (context, widget) => includeDoublePane ? DoubleColumnView() : ContactsView(), );