flutter
Hide keyboard on scroll in Flutter
The ScrollView widget now has a keyboardDismissBehavior attribute that you can use for this purpose. The attribute is inherited by ListView, GridView and CustomScrollView. The attribute defaults to ScrollViewKeyboardDismissBehavior.manual but can be changed to ScrollViewKeyboardDismissBehavior.onDrag. https://api.flutter.dev/flutter/widgets/ScrollView/keyboardDismissBehavior.html Example ListView.builder( keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag, itemCount: itemCount, itemBuilder: (BuildContext context, int index) { return ListTile( title: Text(‘Item ${index + 1}’), … Read more
What is the purpose of a factory method in flutter/dart?
You have it correct! You can read more about factory constructors here: https://dart.dev/guides/language/language-tour#factory-constructors
How to find unused flutter classes in Android Studio or Visual Studio Code
Dart code metrics https://pub.dev/packages/dart_code_metrics supports finding unused files for flutter. As commented by in 2023, unfortunately, it is not free anymore https://dcm.dev/pricing/. To purchase a license, see their website. install: flutter pub add –dev dart_code_metrics run “flutter packages get” or use your IDE to “Pub get”. run: flutter pub run dart_code_metrics:metrics check-unused-files lib result: Unused … Read more
Flutter web does “hot restart” instead of “hot reload”. Is “hot reload” supported on flutter web?
As per the FAQ of Flutter web hot reload is not supported yet. So we have to wait for some more time.
How to remove a card’s inner padding in flutter?
I just want to leave a full code removing the default margin to make it clear Card( margin: EdgeInsets.zero, clipBehavior: Clip.antiAlias, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8.0), ), elevation: 4, child: Image.network( model.item.image, width: 20, height: 200, alignment: Alignment.center, fit: BoxFit.cover, ),
flutter open images from file path
The Image class has a file constructor for that https://api.flutter.dev/flutter/widgets/Image/Image.file.html Image.file(File(path))
How to play sound on button press
Add audioplayers as a dependency and your audio file to pubspec.yaml file like this: dependencies: audioplayers: ^1.0.1 flutter: assets: – assets/audio/my_audio.mp3 Full code (Null-safe): class _HomePageState extends State<HomePage> { @override Widget build(BuildContext context) { return Scaffold( body: ElevatedButton( onPressed: () => AudioPlayer().play(AssetSource(‘audio/my_audio.mp3’)); child: Text(‘Play’), ), ); } }