mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
feat: add environment variable substitution support for auth models
This commit is contained in:
@@ -1,44 +1,33 @@
|
||||
import 'dart:math';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import '../screens/common_widgets/env_trigger_field.dart';
|
||||
|
||||
class AuthTextField extends StatefulWidget {
|
||||
class EnvAuthField extends StatefulWidget {
|
||||
final String hintText;
|
||||
final String? title;
|
||||
final TextEditingController controller;
|
||||
final bool isObscureText;
|
||||
final Function(String)? onChanged;
|
||||
final bool readOnly;
|
||||
final String? infoText;
|
||||
final String? initialValue;
|
||||
|
||||
const AuthTextField(
|
||||
const EnvAuthField(
|
||||
{super.key,
|
||||
this.title,
|
||||
required this.hintText,
|
||||
required this.controller,
|
||||
required this.onChanged,
|
||||
this.readOnly = false,
|
||||
this.isObscureText = false,
|
||||
this.infoText});
|
||||
this.infoText,
|
||||
this.initialValue});
|
||||
|
||||
@override
|
||||
State<AuthTextField> createState() => _AuthFieldState();
|
||||
State<EnvAuthField> createState() => _AuthFieldState();
|
||||
}
|
||||
|
||||
class _AuthFieldState extends State<AuthTextField> {
|
||||
late bool _obscureText;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_obscureText = widget.isObscureText;
|
||||
}
|
||||
|
||||
void _toggleVisibility() {
|
||||
setState(() {
|
||||
_obscureText = !_obscureText;
|
||||
});
|
||||
}
|
||||
|
||||
class _AuthFieldState extends State<EnvAuthField> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AutofillGroup(
|
||||
@@ -67,49 +56,20 @@ class _AuthFieldState extends State<AuthTextField> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
TextFormField(
|
||||
readOnly: widget.readOnly,
|
||||
controller: widget.controller,
|
||||
EnvironmentTriggerField(
|
||||
keyId: "auth-${widget.title ?? widget.hintText}-${Random.secure()}",
|
||||
onChanged: widget.readOnly ? null : widget.onChanged,
|
||||
initialValue: widget.initialValue,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
fontSize: Theme.of(context).textTheme.bodyMedium?.fontSize,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).colorScheme.surfaceContainerLowest,
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.sizeOf(context).width - 80),
|
||||
contentPadding: kP10,
|
||||
decoration: getTextFieldInputDecoration(
|
||||
Theme.of(context).colorScheme,
|
||||
hintText: widget.hintText,
|
||||
hintStyle: Theme.of(context).textTheme.bodySmall,
|
||||
suffixIcon: widget.isObscureText
|
||||
? IconButton(
|
||||
icon: Icon(
|
||||
_obscureText ? Icons.visibility_off : Icons.visibility,
|
||||
size: 20,
|
||||
),
|
||||
onPressed: _toggleVisibility,
|
||||
)
|
||||
: null,
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
),
|
||||
isDense: true,
|
||||
contentPadding: kIsMobile ? kPh6b12 : null,
|
||||
),
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
return "${widget.hintText} cannot be empty!";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
obscureText: _obscureText,
|
||||
onChanged: widget.onChanged,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user