flutter-freaccess-hub/lib/components/templates_components/details_component/details_component_widget.dart

296 lines
13 KiB
Dart

import 'dart:collection';
import 'dart:developer';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hub/components/templates_components/details_component/details_component_model.dart';
import 'package:hub/flutter_flow/flutter_flow_icon_button.dart';
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import 'package:hub/flutter_flow/flutter_flow_util.dart';
import 'package:hub/flutter_flow/internationalization.dart';
import 'package:provider/provider.dart';
class VisitRequestTemplateComponentWidget extends StatefulWidget {
const VisitRequestTemplateComponentWidget({
Key? key,
required this.labelsHashMap,
required this.statusHashMap,
required this.imagePath,
this.onTapCardItemAction,
required this.buttons,
});
final Map<String, String> labelsHashMap;
final List<Map<String, Color>?> statusHashMap;
final String? imagePath;
final Future Function()? onTapCardItemAction;
final List<Widget> buttons;
@override
State<VisitRequestTemplateComponentWidget> createState() =>
_VisitRequestTemplateComponentWidgetState();
}
class _VisitRequestTemplateComponentWidgetState
extends State<VisitRequestTemplateComponentWidget> {
late VisitRequestTemplateComponentModel _model;
LinkedHashMap<String, String> get labelsLinkedHashMap =>
LinkedHashMap.from(widget.labelsHashMap ?? {});
List<LinkedHashMap<String, Color>> get statusLinkedHashMap =>
widget.statusHashMap
.map((map) => LinkedHashMap<String, Color>.from(map ?? {}))
.toList();
@override
void setState(VoidCallback callback) {
super.setState(callback);
_model.onUpdate();
}
@override
void initState() {
super.initState();
_model = createModel(context, () => VisitRequestTemplateComponentModel());
_model.textFieldFocusNodeStatus ??= FocusNode();
}
@override
void dispose() {
_model.maybeDispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
context.watch<FFAppState>();
return LayoutBuilder(
builder: (context, constraints) {
final maxWidth = constraints.maxWidth;
final maxHeight = constraints.maxHeight;
return Container(
width: maxWidth,
decoration: BoxDecoration(
color: FlutterFlowTheme.of(context).primaryBackground,
borderRadius: const BorderRadius.all(Radius.circular(25.0)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
width: maxWidth * 0.3,
height: maxWidth * 0.3,
clipBehavior: Clip.antiAlias,
decoration: const BoxDecoration(
shape: BoxShape.circle,
),
child: CachedNetworkImage(
fadeInDuration: const Duration(milliseconds: 100),
fadeOutDuration: const Duration(milliseconds: 100),
imageUrl: widget.imagePath ?? '',
fit: BoxFit.cover,
),
),
Row(
children: statusLinkedHashMap.expand((linkedHashMap) {
return linkedHashMap.entries
.map((MapEntry<String, Color> item) {
return Expanded(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: maxWidth * 0.05,
),
child: TextFormField(
// controller: _model.textControllerStatus,
// focusNode: _model.textFieldFocusNodeStatus,
autofocus: false,
canRequestFocus: false,
readOnly: true,
obscureText: false,
decoration: InputDecoration(
isDense: true,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(
color: item.value,
),
),
filled: true,
fillColor: item.value,
labelText: item.key,
labelStyle: FlutterFlowTheme.of(context)
.labelMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.labelMediumFamily,
fontWeight: FontWeight.bold,
color: FlutterFlowTheme.of(context).info,
letterSpacing: 0.0,
useGoogleFonts:
GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context)
.labelMediumFamily,
),
),
hintStyle: FlutterFlowTheme.of(context)
.labelMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.labelMediumFamily,
color: FlutterFlowTheme.of(context).info,
letterSpacing: 0.0,
useGoogleFonts:
GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context)
.labelMediumFamily,
),
),
focusedBorder: InputBorder.none,
errorBorder: InputBorder.none,
focusedErrorBorder: InputBorder.none,
suffixIcon: Icon(
Icons.info,
color: FlutterFlowTheme.of(context).info,
),
),
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.bodyMediumFamily,
color: FlutterFlowTheme.of(context).info,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context).bodyMediumFamily,
),
),
textAlign: TextAlign.start,
maxLines: null,
keyboardType: TextInputType.name,
validator: _model.textController1Validator
.asValidator(context),
),
),
);
}).toList();
}).toList(),
),
ListView.builder(
shrinkWrap: true,
itemCount: labelsLinkedHashMap.length,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
String key = labelsLinkedHashMap.keys.elementAt(index);
String value = labelsLinkedHashMap[key]!;
// return Text('key: $key, value: $value');
return Padding(
padding: EdgeInsets.symmetric(
horizontal: maxWidth * 0.02,
vertical: maxHeight * 0.01,
),
child: TextFormField(
readOnly: true,
initialValue: '$value',
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily:
FlutterFlowTheme.of(context).bodyMediumFamily,
color: FlutterFlowTheme.of(context).primaryText,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context).bodyMediumFamily,
),
),
decoration: InputDecoration(
labelText: key,
filled: true,
fillColor:
FlutterFlowTheme.of(context).primaryBackground,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(
color: FlutterFlowTheme.of(context)
.primaryBackground, // Change border color here
),
),
labelStyle: FlutterFlowTheme.of(context)
.labelMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.labelMediumFamily,
color: FlutterFlowTheme.of(context).primaryText,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context).labelMediumFamily,
),
),
hintStyle: FlutterFlowTheme.of(context)
.labelMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.labelMediumFamily,
color: FlutterFlowTheme.of(context).primaryText,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context).labelMediumFamily,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(
color: FlutterFlowTheme.of(context)
.primaryBackground, // Change border color here
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(
color: FlutterFlowTheme.of(context)
.primaryBackground, // Change border color here
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(
color: FlutterFlowTheme.of(context)
.primaryBackground, // Change border color here
),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(
color: FlutterFlowTheme.of(context)
.primaryBackground, // Change border color here
),
),
),
),
);
},
),
if (widget.buttons.isNotEmpty)
Padding(
padding: EdgeInsets.symmetric(
horizontal: maxWidth * 0.02,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: widget.buttons,
),
),
]
.divide(const Flexible(child: SizedBox(height: 20.0)))
.addToEnd(const Flexible(child: SizedBox(height: 20.0)))
.addToStart(const Flexible(child: SizedBox(height: 20.0))),
),
);
},
);
}
}