Open cddqssc opened 6 months ago
Yes, this is probably not actually in the same scope as the setState
you're using. For this, you can look into using any state management solution you'd like. I'd suggest you try to use StatefulBuilder
(which gives you its own setState
function), ValueListenableBuilder
with a ValueNotifier
(my preferred option) or even Stream
s for Dart/Flutter built-in support.
Little example:
import 'package:flutter/material.dart';
void main() => runApp(
const MaterialApp(
home: MyHomePage(),
),
);
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
ValueNotifier<int> _counter = ValueNotifier<int>(0);
void _incrementCounter() {
_counter.value++;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Demo Home Page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'You have pushed the button this many times:',
),
ValueListenableBuilder(
valueListenable: _counter,
builder: (context, value, _) {
return Text(
'$value',
style: Theme.of(context).textTheme.headlineMedium,
);
}
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
Please let me know if you were able to solve your problem!
Thank you for providing such a useful plugin. I want to know how to update the content of floatingChild: Such as:
When str has changed and setstate has been called, the str in FloatingOverlay has not changed. The str display is updated only when resize or position is moved.