Repository: fyne-io/fyne
File: dialog/file.go (Go)

Code before:
	if f.view == gridView {
		f.files = widget.NewGridWrap(count, template,
			func(id widget.GridWrapItemID, o fyne.CanvasObject) {
				dir := f.data[id]
				parent := id == 0 && len(dir.Path()) < len(f.dir.Path())
				_, isDir := dir.(fyne.ListableURI)
				o.(*fileDialogItem).setLocation(dir, isDir || parent, parent)
			},
		)
		f.files.(*widget.GridWrap).OnSelected = func(id widget.GridWrapItemID) {
			f.selectedID = id
			f.setSelected(f.data[id], id)
		}
	} else {
		f.files = widget.NewList(count, template,
			func(id widget.ListItemID, o fyne.CanvasObject) {
				dir := f.data[id]
				parent := id == 0 && dir != f.dir
				_, isDir := dir.(fyne.ListableURI)
				o.(*fileDialogItem).setLocation(dir, isDir, parent)
			},
		)
		f.files.(*widget.List).OnSelected = func(id widget.ListItemID) {
			f.selectedID = id
			f.setSelected(f.data[id], id)
		}
	}
	if f.dir != nil {
		f.refreshDir(f.dir)
	}
	f.filesScroll.Content = container.NewPadded(f.files)
	f.filesScroll.Refresh()
}

// effectiveStartingDir calculates the directory at which the file dialog should
// open, based on the values of startingDirectory, CWD, home, and any error
// conditions which occur.
//
// Order of precedence is:
//
//   - file.startingDirectory if non-empty, os.Stat()-able, and uses the file://
//     URI scheme
//   - os.UserHomeDir()
//   - os.Getwd()
//   - "/" (should be filesystem root on all supported platforms)
func (f *FileDialog) effectiveStartingDir() fyne.ListableURI {
	if f.startingLocation != nil {
		if f.startingLocation.Scheme() == "file" {
			path := f.startingLocation.Path()

			// the starting directory is set explicitly

Review comment (suggestion):
If you use a `&widget.List{}` type here, you can avoid having to cast the variable to get the `OnSelected` field and just set all of the functions directly instead. 

Code after:
	count := func() int {
		return len(f.data)
	}
	template := func() fyne.CanvasObject {
		return f.newFileItem(storage.NewFileURI("./tempfile"), true, false)
	}
	update := func(id widget.GridWrapItemID, o fyne.CanvasObject) {
		dir := f.data[id]
		parent := id == 0 && len(dir.Path()) < len(f.dir.Path())
		_, isDir := dir.(fyne.ListableURI)
		o.(*fileDialogItem).setLocation(dir, isDir || parent, parent)
	}
	choose := func(id int) {
		f.selectedID = id
		f.setSelected(f.data[id], id)
	}
	if f.view == gridView {
		grid := widget.NewGridWrap(count, template, update)
		grid.OnSelected = choose
		f.files = grid
	} else {
		list := widget.NewList(count, template, update)
		list.OnSelected = choose
		f.files = list
	}
	if f.dir != nil {
		f.refreshDir(f.dir)
	}
	f.filesScroll.Content = container.NewPadded(f.files)
	f.filesScroll.Refresh()
}

// effectiveStartingDir calculates the directory at which the file dialog should
// open, based on the values of startingDirectory, CWD, home, and any error
// conditions which occur.
//
// Order of precedence is:
//
//   - file.startingDirectory if non-empty, os.Stat()-able, and uses the file://
//     URI scheme
//   - os.UserHomeDir()
//   - os.Getwd()
//   - "/" (should be filesystem root on all supported platforms)
func (f *FileDialog) effectiveStartingDir() fyne.ListableURI {
	if f.startingLocation != nil {
		if f.startingLocation.Scheme() == "file" {
			path := f.startingLocation.Path()

			// the starting directory is set explicitly
			if _, err := os.Stat(path); err != nil {
				fyne.LogError("Error with StartingLocation", err)