-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from AdrianMargineanu/edit_profile
Edit profile
- Loading branch information
Showing
23 changed files
with
656 additions
and
288 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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import 'package:acs_upb_mobile/pages/filter/model/filter.dart'; | ||
import 'package:acs_upb_mobile/pages/filter/service/filter_provider.dart'; | ||
import 'package:acs_upb_mobile/resources/locale_provider.dart'; | ||
import 'package:acs_upb_mobile/widgets/form/form.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class DropdownTreeController { | ||
_DropdownTreeState _dropdownTreeState; | ||
|
||
List<String> get path => | ||
_dropdownTreeState.nodes.map((e) => e.name).skip(1).toList(); | ||
} | ||
|
||
class DropdownTree extends StatefulWidget { | ||
final List<String> initialPath; | ||
final double leftPadding; | ||
final DropdownTreeController controller; | ||
|
||
DropdownTree({ | ||
Key key, | ||
this.initialPath, | ||
this.leftPadding, | ||
this.controller, | ||
}) : super(key: key); | ||
|
||
@override | ||
_DropdownTreeState createState() => _DropdownTreeState(); | ||
} | ||
|
||
class _DropdownTreeState extends State<DropdownTree> { | ||
List<FormItem> formItems; | ||
FilterProvider filterProvider; | ||
Filter filter; | ||
List<FilterNode> nodes; | ||
|
||
List<Widget> _buildDropdowns(BuildContext context) { | ||
List<Widget> items = [SizedBox(height: 8)]; | ||
for (var i = 0; i < nodes.length; i++) { | ||
if (nodes[i] != null && nodes[i].children.isNotEmpty) { | ||
items.add(Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: <Widget>[ | ||
Padding( | ||
padding: | ||
EdgeInsets.only(top: 8.0, left: widget.leftPadding ?? 0.0), | ||
child: Text( | ||
filter.localizedLevelNames[i][LocaleProvider.localeString], | ||
style: Theme.of(context) | ||
.textTheme | ||
.caption | ||
.apply(color: Theme.of(context).hintColor), | ||
), | ||
), | ||
DropdownButtonFormField<FilterNode>( | ||
value: nodes.length > i + 1 ? nodes[i + 1] : null, | ||
items: nodes[i] | ||
.children | ||
.map((node) => DropdownMenuItem( | ||
value: node, | ||
child: Padding( | ||
padding: EdgeInsets.only( | ||
top: 8.0, left: widget.leftPadding ?? 0.0), | ||
child: Text(node.name), | ||
), | ||
)) | ||
.toList(), | ||
onChanged: (selected) => setState( | ||
() { | ||
nodes.removeRange(i + 1, nodes.length); | ||
nodes.add(selected); | ||
}, | ||
), | ||
), | ||
], | ||
)); | ||
} | ||
} | ||
return items; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
widget.controller?._dropdownTreeState = this; | ||
|
||
return FutureBuilder( | ||
future: Provider.of<FilterProvider>(context).fetchFilter(context), | ||
builder: (BuildContext context, AsyncSnapshot snap) { | ||
if (snap.hasData) { | ||
filter = snap.data; | ||
nodes ??= widget.initialPath == null | ||
? [filter.root] | ||
: filter.findNodesByPath(widget.initialPath); | ||
return Column( | ||
children: _buildDropdowns(context), | ||
); | ||
} | ||
return Center(child: CircularProgressIndicator()); | ||
}, | ||
); | ||
} | ||
} |
Oops, something went wrong.