-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+
- Loading branch information
Showing
4 changed files
with
251 additions
and
65 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
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
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 |
---|---|---|
@@ -1,58 +1,207 @@ | ||
// ignore_for_file: lines_longer_than_80_chars, always_specify_types | ||
|
||
import 'package:api_client/models/displayname_model.dart'; | ||
import 'package:api_client/models/week_model.dart'; | ||
import 'package:api_client/models/week_name_model.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:weekplanner/blocs/new_weekplan_bloc.dart'; | ||
import 'package:weekplanner/di.dart'; | ||
import 'package:weekplanner/routes.dart'; | ||
import 'package:weekplanner/widgets/giraf_app_bar_widget.dart'; | ||
import 'package:weekplanner/widgets/giraf_button_widget.dart'; | ||
import 'package:weekplanner/widgets/input_fields_weekplan.dart'; | ||
|
||
/// Screen for creating a new weekplan. | ||
// ignore: public_member_api_docs | ||
class NewWeekplanScreen extends StatelessWidget { | ||
/// Screen for creating a new weekplan. | ||
/// Requires a [UsernameModel] to be able to save the new weekplan. | ||
|
||
// ignore: public_member_api_docs | ||
NewWeekplanScreen({ | ||
@required DisplayNameModel user, | ||
@required this.user, | ||
@required this.existingWeekPlans, | ||
}) : _bloc = di.get<NewWeekplanBloc>() { | ||
_bloc.initialize(user); | ||
} | ||
|
||
/// Stream of existing week plans. | ||
// ignore: public_member_api_docs | ||
final DisplayNameModel user; | ||
// ignore: public_member_api_docs | ||
final Stream<List<WeekNameModel>> existingWeekPlans; | ||
final NewWeekplanBloc _bloc; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final GirafButton saveButton = GirafButton( | ||
icon: const ImageIcon(AssetImage('assets/icons/save.png')), | ||
key: const Key('NewWeekplanSaveBtnKey'), | ||
text: 'Gem ugeplan', | ||
isEnabled: false, | ||
isEnabledStream: _bloc.allInputsAreValidStream, | ||
onPressed: () async { | ||
final WeekModel newWeekPlan = await _bloc.saveWeekplan( | ||
screenContext: context, | ||
existingWeekPlans: existingWeekPlans, | ||
); | ||
try { | ||
if (newWeekPlan != null) { | ||
Routes().pop<WeekModel>(context, newWeekPlan); | ||
} | ||
} catch (err) { | ||
print('No new weekplan exists' '\n Error: ' + err.toString()); | ||
} | ||
}, | ||
); | ||
final Size screenSize = MediaQuery.of(context).size; | ||
|
||
return Scaffold( | ||
appBar: GirafAppBar(title: 'Ny ugeplan'), | ||
body: InputFieldsWeekPlan( | ||
bloc: _bloc, | ||
button: saveButton, | ||
body: Row( | ||
children: [ | ||
Expanded( | ||
flex: 1, | ||
child: Container( | ||
child: Stack( | ||
children: <Widget>[ | ||
Image.asset( | ||
'assets/icons/giraf_blue_long.png', | ||
repeat: ImageRepeat.repeat, | ||
height: screenSize.height, | ||
fit: BoxFit.cover, | ||
), | ||
Container( | ||
padding: const EdgeInsets.all(20.0), | ||
child: Column( | ||
children: <Widget>[ | ||
Align( | ||
alignment: Alignment.center, | ||
// ignore: duplicate_ignore | ||
child: Container( | ||
padding: const EdgeInsets.all(10.0), | ||
decoration: BoxDecoration( | ||
color: Colors.white, | ||
border: Border.all(color: Colors.black, width: 2.0), | ||
borderRadius: BorderRadius.circular(10.0), | ||
), | ||
child: Builder( | ||
builder: (BuildContext context) { | ||
return IconButton( | ||
key: const Key('NavigationMenu'), | ||
padding: const EdgeInsets.all(0.0), | ||
color: Colors.black, | ||
icon: const Icon(Icons.menu, size: 60), | ||
onPressed: () { | ||
Scaffold.of(context).openDrawer(); | ||
}, | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
Expanded( | ||
flex: 5, | ||
child: InputFieldsWeekPlan( | ||
bloc: _bloc, button: null, | ||
), | ||
), | ||
Expanded( | ||
flex: 1, | ||
child: Container( | ||
child: Stack( | ||
children: <Widget>[ | ||
Image.asset( | ||
'assets/icons/giraf_blue_long.png', | ||
repeat: ImageRepeat.repeat, | ||
height: screenSize.height, | ||
fit: BoxFit.cover, | ||
), | ||
Container( | ||
padding: const EdgeInsets.all(20.0), | ||
child: Column( | ||
children: <Widget>[ | ||
Align( | ||
alignment: Alignment.center, | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Container( | ||
padding: const EdgeInsets.all(10.0), | ||
decoration: BoxDecoration( | ||
color: Colors.white, | ||
border: Border.all(color: Colors.black, width: 2.0), | ||
borderRadius: BorderRadius.circular(10.0), | ||
), | ||
child: IconButton( | ||
key: const Key('CheckIcon'), | ||
padding: const EdgeInsets.all(0.0), | ||
color: Colors.black, // Icon color | ||
icon: const Icon(Icons.check, size: 60), | ||
onPressed: () async { | ||
final WeekModel newWeekPlan = await _bloc.saveWeekplan( | ||
screenContext: context, | ||
existingWeekPlans: existingWeekPlans, | ||
); | ||
try { | ||
if (newWeekPlan != null) { | ||
Routes().pop<WeekModel>(context, newWeekPlan); | ||
} | ||
} catch (err) { | ||
print('No new weekplan exists' '\n Error: ' + err.toString()); | ||
} | ||
}, | ||
), | ||
), | ||
const SizedBox(height: 30), | ||
Container( | ||
padding: const EdgeInsets.all(10.0), | ||
decoration: BoxDecoration( | ||
color: Colors.white, | ||
border: Border.all(color: Colors.black, width: 2.0), | ||
borderRadius: BorderRadius.circular(10.0), | ||
), | ||
child: IconButton( | ||
key: const Key('CloseIcon'), | ||
padding: const EdgeInsets.all(0.0), | ||
color: Colors.black, // Icon color | ||
icon: const Icon(Icons.close, size: 60), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
drawer: Drawer( | ||
child: ListView( | ||
children: [ | ||
ListTile( | ||
leading: const Icon(Icons.home), | ||
title: const Text('Ugeplaner'), | ||
onTap: () { | ||
Navigator.pop(context); | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
ListTile( | ||
leading: const Icon(Icons.person), | ||
title: const Text('Profil'), | ||
onTap: () { | ||
Navigator.pop(context); | ||
Navigator.pushNamed(context, '/profil'); | ||
|
||
}, | ||
), | ||
ListTile( | ||
leading: const Icon(Icons.person), | ||
title: const Text('Skift bruger'), | ||
onTap: () { | ||
Navigator.pop(context); | ||
Navigator.pushNamed(context, '/skift bruger'); | ||
}, | ||
), | ||
ListTile( | ||
leading: const Icon(Icons.exit_to_app), | ||
title: const Text('Log af'), | ||
onTap: () { | ||
Navigator.pop(context); | ||
Navigator.pushNamed(context, '/log af'); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
|
||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.