-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix add schedule drawer as separate widget
- Loading branch information
1 parent
9ba535c
commit a4f7636
Showing
2 changed files
with
212 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:octopus/octopus.dart'; | ||
import 'package:uneconly/common/localization/localization.dart'; | ||
import 'package:uneconly/common/model/dependencies.dart'; | ||
import 'package:uneconly/common/routing/routes.dart'; | ||
import 'package:uneconly/feature/schedule/bloc/schedule_bloc.dart'; | ||
import 'package:uneconly/feature/schedule/widget/schedule_page.dart'; | ||
import 'package:uneconly/feature/select/model/group.dart'; | ||
import 'package:uneconly/feature/select/widget/select_page.dart'; | ||
|
||
/// {@template home_drawer} | ||
/// HomeDrawer widget | ||
/// {@endtemplate} | ||
class ScheduleDrawer extends StatelessWidget { | ||
final List<Group> favoriteGroups; | ||
final VoidCallback onFavoriteGroupsRefresh; | ||
|
||
/// {@macro home_drawer} | ||
const ScheduleDrawer({ | ||
super.key, | ||
required this.favoriteGroups, | ||
required this.onFavoriteGroupsRefresh, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocBuilder<ScheduleBLoC, ScheduleState>( | ||
builder: (context, state) { | ||
return Drawer( | ||
semanticLabel: AppLocalizations.of(context)!.options, | ||
child: ListView( | ||
children: [ | ||
DrawerHeader( | ||
margin: EdgeInsets.zero, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text( | ||
AppLocalizations.of(context)!.selectedGroup, | ||
style: const TextStyle( | ||
fontSize: 24, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
const SizedBox(height: 8), | ||
Text( | ||
state.shortGroupInfo?.groupName ?? '', | ||
style: const TextStyle( | ||
fontSize: 20, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
ListTile( | ||
title: Text( | ||
AppLocalizations.of(context)!.selectAnotherGroup, | ||
), | ||
onTap: () { | ||
Octopus.of(context).push( | ||
Routes.select, | ||
); | ||
}, | ||
), | ||
// ListTile for settings | ||
ListTile( | ||
title: Text( | ||
AppLocalizations.of(context)!.settings, | ||
), | ||
onTap: () { | ||
Octopus.of( | ||
context, | ||
).push( | ||
Routes.settings, | ||
); | ||
}, | ||
), | ||
// ListTile to view schedule of another group | ||
ListTile( | ||
title: Text( | ||
AppLocalizations.of(context)!.viewScheduleOfAnotherGroup, | ||
), | ||
onTap: () async { | ||
final octopus = context.octopus; | ||
|
||
await octopus.push( | ||
Routes.select, | ||
arguments: { | ||
'mode': 'view', | ||
}, | ||
); | ||
|
||
await waitReturnToHomeSchedule( | ||
octopus, | ||
); | ||
|
||
onFavoriteGroupsRefresh(); | ||
}, | ||
), | ||
// Title for lisview of favorite groups | ||
ListTile( | ||
title: Text( | ||
AppLocalizations.of(context)!.favoriteGroups, | ||
// heading style | ||
style: const TextStyle( | ||
fontSize: 20, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
), | ||
// If there are no favorite groups show button to add one | ||
if (favoriteGroups.isEmpty) | ||
ListTile( | ||
title: Text( | ||
AppLocalizations.of(context)!.addFirstFavoriteGroup, | ||
), | ||
), | ||
|
||
// Listview to view favorite groups | ||
if (favoriteGroups.isNotEmpty) | ||
ListView.builder( | ||
shrinkWrap: true, | ||
physics: const NeverScrollableScrollPhysics(), | ||
itemCount: favoriteGroups.length, | ||
itemBuilder: (context, index) { | ||
return ListTile( | ||
title: Text( | ||
favoriteGroups[index].name, | ||
), | ||
onTap: () async { | ||
final octopus = context.octopus; | ||
final dependenciesScope = Dependencies.of(context); | ||
|
||
await octopus.push( | ||
Routes.schedule, | ||
arguments: { | ||
'groupId': favoriteGroups[index].id.toString(), | ||
'groupName': favoriteGroups[index].name, | ||
'isViewMode': 'true', | ||
}, | ||
); | ||
|
||
await waitReturnToHomeSchedule(octopus); | ||
|
||
onFavoriteGroupsRefresh(); | ||
}, | ||
); | ||
}, | ||
), | ||
// Elevated Button with minimum possible width to add favorite group | ||
Align( | ||
alignment: Alignment.centerLeft, | ||
child: Container( | ||
width: 132, | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: 16, | ||
), | ||
child: ElevatedButton( | ||
onPressed: () async { | ||
final octopus = context.octopus; | ||
|
||
await octopus.push( | ||
Routes.select, | ||
arguments: { | ||
'mode': SelectPageMode.favorite.name, | ||
}, | ||
); | ||
|
||
await waitReturnToHomeSchedule(octopus); | ||
|
||
onFavoriteGroupsRefresh(); | ||
}, | ||
child: Text( | ||
AppLocalizations.of(context)!.add, | ||
), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} // HomeDrawer |
Oops, something went wrong.