the keyword final in dart refers to runtime constant meaning, the value can change at the time of compiling but not during the run time. 

 

final word;

the word can be anything prior to runtime but once it's set in the runtime you can not change it, as oppose to const which is a compile-time constant meaning the value should be known during the time of compilation. 

 

how to pass a function into another widget in flutter? 

 I have a function that accepts a function to take care of business when the button is pressed. 

here is the widget that has two text fields that work as form inputs and a flat button to take the input and submit the results. 

the submit function is one of the parameters.

import 'package:flutter/material.dart';

class NewTransaction extends StatelessWidget {
  final Function submitFunction;

  NewTransaction({this.submitFunction});

  final titleInput = TextEditingController();
  final amountInputController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Card(
      child: Container(
        child: Column(
          children: [
            TextField(
              decoration: InputDecoration(labelText: 'Title'),
              controller: titleInput,
            ),
            TextField(
              decoration: InputDecoration(labelText: 'Amount'),
              controller: amountInputController,
            ),
            FlatButton(
                onPressed: () {
                  submitFunction(titleInput.text,
                      double.parse(amountInputController.text));
                  print(titleInput.text);
                  print(amountInputController.text);
                },
                child: Text('Add Transaction')),
          ],
        ),
      ),
    );
  }
}

 

 

and here is where the widget above is being used:

import 'package:flutter/material.dart';
import '../models/transaction.dart';
import './new_transaction.dart';
import './transactions_list.dart';

class UserTransactions extends StatefulWidget {
  @override
  _UserTransactionsState createState() => _UserTransactionsState();
}

class _UserTransactionsState extends State<UserTransactions> {
  final List<Transaction> _transactions = [
    Transaction(
        id: 't1', title: 'New Shoes', amount: 19.99, date: DateTime.now()),
    Transaction(
        id: 't2', title: 'Groceries', amount: 30.99, date: DateTime.now()),
  ];

  void _addNewTransaction(String txTitle, double txAmount) {
    final newTx = Transaction(
        id: DateTime.now().toString(),
        title: txTitle,
        amount: txAmount,
        date: DateTime.now());

    setState(() {
      _transactions.add(newTx);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        NewTransaction(submitFunction: _addNewTransaction),
        TransactionList(_transactions),
      ],
    );
  }
}