Merge pull request #1540 from abarth/rm_button_state
Remove ButtonState
This commit is contained in:
commit
6111301a9b
@ -151,16 +151,18 @@ class TextureButton extends StatefulComponent {
|
||||
TextureButtonState createState() => new TextureButtonState();
|
||||
}
|
||||
|
||||
class TextureButtonState extends ButtonState<TextureButton> {
|
||||
Widget buildContent(BuildContext context) {
|
||||
return new Listener(
|
||||
class TextureButtonState extends State<TextureButton> {
|
||||
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<TextureButton> {
|
||||
)
|
||||
)
|
||||
),
|
||||
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<TextureButton> {
|
||||
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());
|
||||
|
@ -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<T extends StatefulComponent> extends State<T> {
|
||||
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);
|
||||
}
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user