Skip to content

Instantly share code, notes, and snippets.

@gspencergoog
Created January 24, 2023 20:38
Show Gist options
  • Select an option

  • Save gspencergoog/ac2a707ab259db2ab06989411f661370 to your computer and use it in GitHub Desktop.

Select an option

Save gspencergoog/ac2a707ab259db2ab06989411f661370 to your computer and use it in GitHub Desktop.
FocusableActionDetector Example
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: HoverBox(),
),
),
);
}
}
class HoverBox extends StatefulWidget {
const HoverBox({super.key});
@override
State<HoverBox> createState() => _HoverBoxState();
}
class _HoverBoxState extends State<HoverBox> {
bool _hovering = false;
@override
Widget build(BuildContext context) {
return FocusableActionDetector(
onShowHoverHighlight: (bool value) { setState(() { _hovering = value; }); },
child: Container(
width: 100, height: 100, color: _hovering ? Colors.red : Colors.blue),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment