-
Notifications
You must be signed in to change notification settings - Fork 14
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 #139 from NobodyForNothing/FEAT-horizontal-lines
Add custom horizontal lines to graph
- Loading branch information
Showing
9 changed files
with
329 additions
and
113 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,80 @@ | ||
import 'package:blood_pressure_app/model/settings_store.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
// TODO: redo dialoges in flutter style | ||
class InputDialoge extends StatefulWidget { | ||
final String hintText; | ||
final void Function(String text) onSubmit; | ||
final List<TextInputFormatter>? inputFormatters; | ||
final TextInputType? keyboardType; | ||
|
||
const InputDialoge({super.key, required this.hintText, required this.onSubmit, this.inputFormatters, this.keyboardType}); | ||
|
||
@override | ||
State<InputDialoge> createState() => _InputDialogeState(); | ||
} | ||
|
||
class _InputDialogeState extends State<InputDialoge> { | ||
final formKey = GlobalKey<FormState>(); | ||
final controller = TextEditingController(); | ||
final inputFocusNode = FocusNode(); | ||
|
||
@override | ||
void dispose() { | ||
// Clean up the controller when the widget is disposed. | ||
controller.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
inputFocusNode.requestFocus(); | ||
return AlertDialog( | ||
content: TextFormField( | ||
key: formKey, | ||
focusNode: inputFocusNode, | ||
controller: controller, | ||
inputFormatters: widget.inputFormatters, | ||
keyboardType: widget.keyboardType, | ||
decoration: InputDecoration(hintText: widget.hintText), | ||
), | ||
actions: [ | ||
Consumer<Settings>(builder: (context, settings, child) { | ||
return ElevatedButton( | ||
onPressed: () { | ||
widget.onSubmit(controller.text); | ||
}, | ||
child: Text(AppLocalizations.of(context)!.btnConfirm) | ||
); | ||
}), | ||
|
||
], | ||
); | ||
} | ||
} | ||
|
||
class NumberInputDialoge extends StatelessWidget { | ||
final String hintText; | ||
final void Function(int text) onParsableSubmit; | ||
|
||
const NumberInputDialoge({super.key, required this.hintText, required this.onParsableSubmit}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return InputDialoge( | ||
hintText: hintText, | ||
inputFormatters: [FilteringTextInputFormatter.digitsOnly], | ||
keyboardType: TextInputType.number, | ||
onSubmit: (text) { | ||
if (text.isEmpty || (int.tryParse(text) == null)) { | ||
return; | ||
} | ||
int value = int.parse(text); | ||
onParsableSubmit(value); | ||
} | ||
); | ||
} | ||
} |
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,17 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class HorizontalGraphLine { | ||
Color color; | ||
int height; | ||
|
||
HorizontalGraphLine(this.color, this.height); | ||
|
||
HorizontalGraphLine.fromJson(Map<String, dynamic> json) | ||
: color = Color(json['color']), | ||
height = json['height']; | ||
|
||
Map<String, dynamic> toJson() => { | ||
'color': color.value, | ||
'height': height, | ||
}; | ||
} |
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.