From 3308ff002610c1ed9e3b89e9d03781aaff4f90dd Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 8 Oct 2015 10:22:33 -0700 Subject: [PATCH] Remove ButtonState Clients should just use a GestureDetector (or an InkWell) instead. --- examples/game/lib/main.dart | 27 ++++++++++--- .../flutter/lib/src/widgets/button_state.dart | 39 ------------------- .../flutter/lib/src/widgets/drawer_item.dart | 1 - .../src/widgets/floating_action_button.dart | 1 - .../lib/src/widgets/material_button.dart | 1 - packages/flutter/lib/widgets.dart | 1 - 6 files changed, 21 insertions(+), 49 deletions(-) delete mode 100644 packages/flutter/lib/src/widgets/button_state.dart diff --git a/examples/game/lib/main.dart b/examples/game/lib/main.dart index 51366d9a40..c8cf7417cb 100644 --- a/examples/game/lib/main.dart +++ b/examples/game/lib/main.dart @@ -151,16 +151,18 @@ class TextureButton extends StatefulComponent { TextureButtonState createState() => new TextureButtonState(); } -class TextureButtonState extends ButtonState { - Widget buildContent(BuildContext context) { - return new Listener( +class TextureButtonState extends State { + bool _highlight = false; + + Widget build(BuildContext context) { + return new GestureDetector( child: new Container( width: config.width, height: config.height, child: new CustomPaint( callback: paintCallback, token: new _TextureButtonToken( - highlight, + _highlight, config.texture, config.textureDown, config.width, @@ -168,9 +170,22 @@ class TextureButtonState extends ButtonState { ) ) ), - onPointerUp: (_) { + onTapDown: () { + setState(() { + _highlight = true; + }); + }, + onTap: () { + setState(() { + _highlight = false; + }); if (config.onPressed != null) config.onPressed(); + }, + onTapCancel: () { + setState(() { + _highlight = false; + }); } ); } @@ -180,7 +195,7 @@ class TextureButtonState extends ButtonState { return; canvas.save(); - if (highlight && config.textureDown != null) { + if (_highlight && config.textureDown != null) { // Draw down state canvas.scale(size.width / config.textureDown.size.width, size.height / config.textureDown.size.height); config.textureDown.drawTexture(canvas, Point.origin, new Paint()); diff --git a/packages/flutter/lib/src/widgets/button_state.dart b/packages/flutter/lib/src/widgets/button_state.dart deleted file mode 100644 index a9c5366cb3..0000000000 --- a/packages/flutter/lib/src/widgets/button_state.dart +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2015 The Chromium 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:sky/src/widgets/basic.dart'; -import 'package:sky/src/widgets/framework.dart'; - -abstract class ButtonState extends State { - bool highlight = false; - - void _handlePointerDown(_) { - setState(() { - highlight = true; - }); - } - - void _handlePointerUp(_) { - setState(() { - highlight = false; - }); - } - - void _handlePointerCancel(_) { - setState(() { - highlight = false; - }); - } - - Widget build(BuildContext context) { - return new Listener( - onPointerDown: _handlePointerDown, - onPointerUp: _handlePointerUp, - onPointerCancel: _handlePointerCancel, - child: buildContent(context) - ); - } - - Widget buildContent(BuildContext context); -} diff --git a/packages/flutter/lib/src/widgets/drawer_item.dart b/packages/flutter/lib/src/widgets/drawer_item.dart index 3c5ca71dec..a963398ce6 100644 --- a/packages/flutter/lib/src/widgets/drawer_item.dart +++ b/packages/flutter/lib/src/widgets/drawer_item.dart @@ -8,7 +8,6 @@ import 'package:sky/gestures.dart'; import 'package:sky/material.dart'; import 'package:sky/painting.dart'; import 'package:sky/src/widgets/basic.dart'; -import 'package:sky/src/widgets/button_state.dart'; import 'package:sky/src/widgets/framework.dart'; import 'package:sky/src/widgets/icon.dart'; import 'package:sky/src/widgets/ink_well.dart'; diff --git a/packages/flutter/lib/src/widgets/floating_action_button.dart b/packages/flutter/lib/src/widgets/floating_action_button.dart index 168b5d053b..8b95422f96 100644 --- a/packages/flutter/lib/src/widgets/floating_action_button.dart +++ b/packages/flutter/lib/src/widgets/floating_action_button.dart @@ -4,7 +4,6 @@ import 'package:sky/gestures.dart'; import 'package:sky/src/widgets/basic.dart'; -import 'package:sky/src/widgets/button_state.dart'; import 'package:sky/src/widgets/framework.dart'; import 'package:sky/src/widgets/icon.dart'; import 'package:sky/src/widgets/ink_well.dart'; diff --git a/packages/flutter/lib/src/widgets/material_button.dart b/packages/flutter/lib/src/widgets/material_button.dart index bbd127c655..4a21d4ebe8 100644 --- a/packages/flutter/lib/src/widgets/material_button.dart +++ b/packages/flutter/lib/src/widgets/material_button.dart @@ -4,7 +4,6 @@ import 'package:sky/gestures.dart'; import 'package:sky/src/widgets/basic.dart'; -import 'package:sky/src/widgets/button_state.dart'; import 'package:sky/src/widgets/framework.dart'; import 'package:sky/src/widgets/ink_well.dart'; import 'package:sky/src/widgets/material.dart'; diff --git a/packages/flutter/lib/widgets.dart b/packages/flutter/lib/widgets.dart index 93eabd8dba..84f308d536 100644 --- a/packages/flutter/lib/widgets.dart +++ b/packages/flutter/lib/widgets.dart @@ -9,7 +9,6 @@ export 'src/widgets/animated_container.dart'; export 'src/widgets/app.dart'; export 'src/widgets/basic.dart'; export 'src/widgets/binding.dart'; -export 'src/widgets/button_state.dart'; export 'src/widgets/card.dart'; export 'src/widgets/checkbox.dart'; export 'src/widgets/date_picker.dart';