@@ -26,8 +26,6 @@ class WindowCaption extends StatefulWidget {
2626}
2727
2828class _WindowCaptionState extends State <WindowCaption > with WindowListener {
29- bool _isMaximized = false ;
30-
3129 @override
3230 void initState () {
3331 windowManager.addListener (this );
@@ -89,20 +87,25 @@ class _WindowCaptionState extends State<WindowCaption> with WindowListener {
8987 }
9088 },
9189 ),
92- if (! _isMaximized)
93- WindowCaptionButton .maximize (
94- brightness: widget.brightness,
95- onPressed: () {
96- windowManager.maximize ();
97- },
98- )
99- else
100- WindowCaptionButton .unmaximize (
101- brightness: widget.brightness,
102- onPressed: () {
103- windowManager.unmaximize ();
104- },
105- ),
90+ FutureBuilder <bool >(
91+ future: windowManager.isMaximized (),
92+ builder: (BuildContext context, AsyncSnapshot <bool > snapshot) {
93+ if (snapshot.data == true ) {
94+ return WindowCaptionButton .unmaximize (
95+ brightness: widget.brightness,
96+ onPressed: () {
97+ windowManager.unmaximize ();
98+ },
99+ );
100+ }
101+ return WindowCaptionButton .maximize (
102+ brightness: widget.brightness,
103+ onPressed: () {
104+ windowManager.maximize ();
105+ },
106+ );
107+ },
108+ ),
106109 WindowCaptionButton .close (
107110 brightness: widget.brightness,
108111 onPressed: () {
@@ -118,13 +121,11 @@ class _WindowCaptionState extends State<WindowCaption> with WindowListener {
118121
119122 @override
120123 void onWindowMaximize () {
121- _isMaximized = true ;
122124 setState (() {});
123125 }
124126
125127 @override
126128 void onWindowUnmaximize () {
127- _isMaximized = false ;
128129 setState (() {});
129130 }
130131}
0 commit comments