Skip to content

Instantly share code, notes, and snippets.

@avuenja
Created July 24, 2020 13:27
Show Gist options
  • Save avuenja/26bb818a8a5c4f964393985fca685ca3 to your computer and use it in GitHub Desktop.
Save avuenja/26bb818a8a5c4f964393985fca685ca3 to your computer and use it in GitHub Desktop.
Flutter: Haptic Feedback
import 'package:flutter/material.dart';
import 'package:flutter_raw/src/utils/haptic.dart'; // Adiciono a linha de importação do util
import 'package:flutter_raw/src/controllers/home.dart';
class HomeView extends StatelessWidget {
final HomeController _homeController = HomeController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
ValueListenableBuilder(
valueListenable: this._homeController.counter,
builder: (_, counter, ___) {
return Text(
'$counter',
style: Theme.of(context).textTheme.headline4,
);
},
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
HapticFeedback.heavyImpact(); // Faço a chamada do HapticFeedback com a intensidade da resposta
this._homeController.incrementCounter();
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment