-
Notifications
You must be signed in to change notification settings - Fork 36
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 #69 from refilc/dev
69-es szamu pr haha 😏
- Loading branch information
Showing
23 changed files
with
272 additions
and
42 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
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
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
122 changes: 122 additions & 0 deletions
122
filcnaplo_desktop_ui/lib/screens/login/school_input/school_input.dart
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,122 @@ | ||
import 'package:filcnaplo_mobile_ui/screens/login/login_input.dart'; | ||
import 'package:filcnaplo_mobile_ui/screens/login/school_input/school_input_overlay.dart'; | ||
import 'package:filcnaplo_desktop_ui/screens/login/school_input/school_input_tile.dart'; | ||
import 'package:filcnaplo_mobile_ui/screens/login/school_input/school_search.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:filcnaplo_kreta_api/models/school.dart'; | ||
|
||
class SchoolInput extends StatefulWidget { | ||
const SchoolInput({Key? key, required this.controller, required this.scroll}) | ||
: super(key: key); | ||
|
||
final SchoolInputController controller; | ||
final ScrollController scroll; | ||
|
||
@override | ||
_SchoolInputState createState() => _SchoolInputState(); | ||
} | ||
|
||
class _SchoolInputState extends State<SchoolInput> { | ||
final _focusNode = FocusNode(); | ||
final _layerLink = LayerLink(); | ||
late SchoolInputOverlay overlay; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
widget.controller.update = (fn) { | ||
if (mounted) setState(fn); | ||
}; | ||
|
||
overlay = SchoolInputOverlay(layerLink: _layerLink); | ||
|
||
// Show school list when focused | ||
_focusNode.addListener(() { | ||
if (_focusNode.hasFocus) { | ||
WidgetsBinding.instance | ||
.addPostFrameCallback((_) => overlay.createOverlayEntry(context)); | ||
Future.delayed(const Duration(milliseconds: 100)).then((value) { | ||
if (mounted && widget.scroll.hasClients) { | ||
widget.scroll.animateTo(widget.scroll.offset + 500, | ||
duration: const Duration(milliseconds: 500), | ||
curve: Curves.ease); | ||
} | ||
}); | ||
} else { | ||
overlay.entry?.remove(); | ||
} | ||
}); | ||
|
||
// LoginInput TextField listener | ||
widget.controller.textController.addListener(() { | ||
String text = widget.controller.textController.text; | ||
if (text.isEmpty) { | ||
overlay.children = null; | ||
return; | ||
} | ||
|
||
List<School> results = | ||
searchSchools(widget.controller.schools ?? [], text); | ||
setState(() { | ||
overlay.children = results | ||
.map((School e) => SchoolInputTile( | ||
school: e, | ||
onTap: () => _selectSchool(e), | ||
)) | ||
.toList(); | ||
}); | ||
Overlay.of(context).setState(() {}); | ||
}); | ||
} | ||
|
||
void _selectSchool(School school) { | ||
FocusScope.of(context).requestFocus(FocusNode()); | ||
|
||
setState(() { | ||
widget.controller.selectedSchool = school; | ||
widget.controller.textController.text = school.name; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CompositedTransformTarget( | ||
link: _layerLink, | ||
child: widget.controller.schools == null | ||
? Container( | ||
width: double.infinity, | ||
padding: const EdgeInsets.symmetric(vertical: 10.0), | ||
decoration: BoxDecoration( | ||
color: Colors.black.withOpacity(0.15), | ||
borderRadius: BorderRadius.circular(12.0), | ||
), | ||
child: const Center( | ||
child: SizedBox( | ||
height: 28.0, | ||
width: 28.0, | ||
child: CircularProgressIndicator( | ||
color: Colors.white, | ||
), | ||
), | ||
), | ||
) | ||
: LoginInput( | ||
style: LoginInputStyle.school, | ||
focusNode: _focusNode, | ||
onClear: () { | ||
widget.controller.selectedSchool = null; | ||
FocusScope.of(context).requestFocus(_focusNode); | ||
}, | ||
controller: widget.controller.textController, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class SchoolInputController { | ||
final textController = TextEditingController(); | ||
School? selectedSchool; | ||
List<School>? schools; | ||
late void Function(void Function()) update; | ||
} |
65 changes: 65 additions & 0 deletions
65
filcnaplo_desktop_ui/lib/screens/login/school_input/school_input_tile.dart
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,65 @@ | ||
import 'package:filcnaplo_kreta_api/models/school.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class SchoolInputTile extends StatelessWidget { | ||
const SchoolInputTile({Key? key, required this.school, this.onTap}) | ||
: super(key: key); | ||
|
||
final School school; | ||
final Function()? onTap; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.all(4.0), | ||
child: GestureDetector( | ||
onPanDown: (e) { | ||
onTap!(); | ||
}, | ||
child: InkWell( | ||
onTapDown: (e) {}, | ||
borderRadius: BorderRadius.circular(6.0), | ||
child: Padding( | ||
padding: const EdgeInsets.all(6.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
// School name | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 4.0), | ||
child: Text( | ||
school.name, | ||
maxLines: 2, | ||
overflow: TextOverflow.ellipsis, | ||
style: const TextStyle(fontWeight: FontWeight.w600), | ||
), | ||
), | ||
Row( | ||
children: [ | ||
// School id | ||
Expanded( | ||
child: Text( | ||
school.instituteCode, | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
), | ||
// School city | ||
Expanded( | ||
child: Text( | ||
school.city, | ||
textAlign: TextAlign.right, | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.