Skip to content

Commit

Permalink
semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
danemadsen committed May 25, 2024
1 parent afa43f4 commit 08663df
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 136 deletions.
241 changes: 126 additions & 115 deletions lib/ui/mobile/widgets/home_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,126 +53,137 @@ class _HomeDrawerState extends State<HomeDrawer> {

@override
Widget build(BuildContext context) {
return Consumer<Session>(
builder: (context, session, child) {
current = session.key;

var contains = false;

for (var element in sessions) {
if (element.key == current) {
contains = true;
break;
}
}

if (!contains) {
sessions.insert(0, session.copy());
}

SharedPreferences.getInstance().then((prefs) {
prefs.setString("last_session", json.encode(session.toMap()));
});

return Drawer(
backgroundColor: Theme.of(context).colorScheme.background,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
bottomRight: Radius.circular(20)
),
),
child: SafeArea(
minimum: const EdgeInsets.all(10.0),
child: Column(children: [
const CharacterTile(),
const SizedBox(height: 5.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FilledButton(
onPressed: () {
Navigator.pop(context); // Close the drawer
Navigator.pushNamed(
context,
'/character'
);
},
child: const Text(
"Customize"
),
return Semantics(
label: "Drawer Menu",
onTapHint: "Close Drawer",
onTap: () {
Navigator.pop(context);
},
child: Consumer<Session>(
builder: drawerBuilder
)
);
}

Widget drawerBuilder(BuildContext context, Session session, Widget? child) {
current = session.key;

var contains = false;

for (var element in sessions) {
if (element.key == current) {
contains = true;
break;
}
}

if (!contains) {
sessions.insert(0, session.copy());
}

SharedPreferences.getInstance().then((prefs) {
prefs.setString("last_session", json.encode(session.toMap()));
});

return Drawer(
semanticLabel: "Drawer Menu",
backgroundColor: Theme.of(context).colorScheme.background,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
bottomRight: Radius.circular(20)
),
),
child: SafeArea(
minimum: const EdgeInsets.all(10.0),
child: Column(
children: [
const CharacterTile(),
const SizedBox(height: 5.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FilledButton(
onPressed: () {
Navigator.pop(context); // Close the drawer
Navigator.pushNamed(
context,
'/character'
);
},
child: const Text(
"Customize"
),
FilledButton(
onPressed: () {
Navigator.pop(context); // Close the drawer
Navigator.pushNamed(
context,
'/characters'
);
},
child: const Text(
"Browse"
),
)
]
),
Divider(
color: Theme.of(context).colorScheme.primary,
),
FilledButton(
onPressed: () {
if (!session.chat.tail.finalised) return;
setState(() {
final newSession = Session();
sessions.add(newSession);
session.from(newSession);
});
},
child: const Text(
"New Chat"
),
),
Divider(
color: Theme.of(context).colorScheme.primary,
),
Expanded(
child: ListView.builder(
itemCount: sessions.length,
itemBuilder: (context, index) {
return SessionTile(
session: sessions[index],
onDelete: () {
if (!session.chat.tail.finalised) return;
setState(() {
if (sessions[index].key == session.key) {
session.from(sessions.firstOrNull ?? Session());
}
sessions.removeAt(index);
});
},
onRename: (value) {
setState(() {
if (sessions[index].key == session.key) {
session.name = value;
}
sessions[index].name = value;
});
},
FilledButton(
onPressed: () {
Navigator.pop(context); // Close the drawer
Navigator.pushNamed(
context,
'/characters'
);
}
),
},
child: const Text(
"Browse"
),
)
]
),
Divider(
color: Theme.of(context).colorScheme.primary,
),
FilledButton(
onPressed: () {
if (!session.chat.tail.finalised) return;
setState(() {
final newSession = Session();
sessions.add(newSession);
session.from(newSession);
});
},
child: const Text(
"New Chat"
),
Divider(
height: 0.0,
color: Theme.of(context).colorScheme.primary,
),
Divider(
color: Theme.of(context).colorScheme.primary,
),
Expanded(
child: ListView.builder(
itemCount: sessions.length,
itemBuilder: (context, index) {
return SessionTile(
session: sessions[index],
onDelete: () {
if (!session.chat.tail.finalised) return;
setState(() {
if (sessions[index].key == session.key) {
session.from(sessions.firstOrNull ?? Session());
}
sessions.removeAt(index);
});
},
onRename: (value) {
setState(() {
if (sessions[index].key == session.key) {
session.name = value;
}
sessions[index].name = value;
});
},
);
}
),
const SizedBox(height: 5.0),
const UserTile()
]
)
)
);
},
),
Divider(
height: 0.0,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 5.0),
const UserTile()
]
)
)
);
}
}
45 changes: 24 additions & 21 deletions lib/ui/mobile/widgets/tiles/user_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,30 @@ class _UserTileState extends State<UserTile> {
@override
Widget build(BuildContext context) {
return Consumer<User>(
builder: (context, user, child) {
return ListTile(
title: Text(
user.name,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
fontSize: 20,
),
),
leading: FutureAvatar(
key: user.key,
image: user.profile,
radius: 20,
),
trailing: IconButton(
key: iconButtonKey,
icon: const Icon(Icons.more_vert),
onPressed: onPressed,
),
);
},
builder: listTileBuilder,
);
}

Widget listTileBuilder(BuildContext context, User user, Widget? child) {
return ListTile(
title: Text(
user.name,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
fontSize: 20,
),
),
leading: FutureAvatar(
key: user.key,
image: user.profile,
radius: 20,
),
trailing: IconButton(
tooltip: 'User Menu',
key: iconButtonKey,
icon: const Icon(Icons.more_vert),
onPressed: onPressed,
),
);
}

Expand Down

0 comments on commit 08663df

Please sign in to comment.