Created with <3 with dartpad.dev.
Last active
June 13, 2023 12:14
-
-
Save hans-min/6b24cbfdf1478e43ce79eb888ed8dc3c to your computer and use it in GitHub Desktop.
onSubmitted: func vs () => func()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark(), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: AppBar( | |
title: const Text("Func vs () => func"), | |
), | |
body: const Center( | |
child: Padding( | |
padding: EdgeInsets.symmetric(horizontal: 20), | |
child: SearchBar(), | |
), | |
), | |
), | |
); | |
} | |
} | |
class SearchBar extends StatelessWidget { | |
const SearchBar({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return TextField( | |
decoration: const InputDecoration( | |
border: OutlineInputBorder(), | |
), | |
//onSubmitted: onSubmit, // Option A works | |
onSubmitted: (value) => onSubmit // Option B doesn't | |
//onSubmitted: (value) => onSubmit(value), // Option C works | |
); | |
} | |
onSubmit(value) => print(value); | |
//try assign onSubmitted: onSubmitNoParam, and see the error | |
onSubmitNoParam() => print("Printed!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment