Replies: 2 comments 6 replies
-
Hey @lvsecoto, please check this doc it will help you to understand how it works https://www.fluttermix.com/docs/tutorials/controlling-widget-state |
Beta Was this translation helpful? Give feedback.
6 replies
-
However, as a quick answer, you will need to do it manually. Take a look at this example code it's a real case usage import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mix/mix.dart';
void main() {
testWidgets(
'description',
(WidgetTester tester) async {
TextStyle style = const TextStyle(color: Color(0xFF000000));
await tester.pumpWidget(
MaterialApp(
home: MyWidget(
(textStyle) => style = textStyle,
),
),
);
expect(style.color, equals(Colors.blue));
await tester.tap(find.text('Selected'));
await tester.pumpAndSettle();
expect(style.color, equals(Colors.red));
},
);
}
class MyWidget extends StatefulWidget {
const MyWidget(
this.callback, {
super.key,
});
final TextStyle Function(TextStyle) callback;
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
late MixWidgetStateController _controller;
@override
void initState() {
super.initState();
_controller = MixWidgetStateController();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Pressable(
onPress: () => _controller.selected = true,
controller: _controller,
child: Box(
style: Style(
$text.style.color.blue(),
$on.selected(
$text.style.color.red(),
),
),
child: Builder(
builder: (context) {
final textStyle = TextSpec.of(context).style;
widget.callback(textStyle!);
return const StyledText('Selected');
},
),
),
);
}
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
but not working...
Beta Was this translation helpful? Give feedback.
All reactions