DEV Community

Paolo Mazzon
Paolo Mazzon

Posted on

How to Manage ForeignKey

Hello, I have a page InsertRepair, I'm using RactiveForm and its widgets, for the choise of customers I used reactiveDropodownSearch that how items use a map of repairs loaded by state.customer.name. How to pass relative id at state.customer.name. (foreign key in table repairs on db) To formControl in main Class. I hope that You understand me.

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:au79dt1_0/blocs/customer/customer_bloc.dart';
import 'package:au79dt1_0/widgets/custom_dropdw_search.dart';
import 'package:reactive_forms/reactive_forms.dart';

class InsertRepairFirstPage extends StatelessWidget {
  final String? controllerUserId;
  final String? controllerCustomerId;

  final FormGroup formGroup;
  const InsertRepairFirstPage(
      {Key? key,
      this.controllerUserId,
      this.controllerCustomerId,
      required this.formGroup})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        DropDownCustomer(
          nameController: controllerCustomerId,
          formGroup: formGroup,
        )
      ],
    );
  }
}

class DropDownCustomer extends StatelessWidget {
  const DropDownCustomer({
    super.key,
    required this.nameController,
    required this.formGroup,
  });

  final String? nameController;
  final FormGroup formGroup;

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<CustomerBloc, CustomerState>(builder: (context, state) {
      if (state is CustomerGetAllLoadedState) {
        return CustomDropDwSearch(
          formControlName: nameController,
          titlePopUp: 'Select Customers',
          labelText: 'Customers',
          items: state.customers
              .map((customer) => customer.name.toString())
              .toList(),
        );
      }
      return Container();
    });
  }
}
Enter fullscreen mode Exit fullscreen mode

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more