Created
March 8, 2022 13:10
-
-
Save huynguyennovem/3cfca809ab417afd78488dc632033f68 to your computer and use it in GitHub Desktop.
IndexedStack lose focused when switching between index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui' show window; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(BugReport()); | |
} | |
class BugReport extends StatefulWidget { | |
@override | |
_BugReportState createState() => _BugReportState(); | |
} | |
class _BugReportState extends State<BugReport> { | |
int selectedIndex = 0; | |
_setIndex(int value) { | |
setState(() { | |
selectedIndex = value; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Localizations( | |
locale: Locale('en', 'US'), | |
delegates: [ | |
DefaultWidgetsLocalizations.delegate, | |
DefaultMaterialLocalizations.delegate, | |
], | |
child: MediaQuery( | |
data: MediaQueryData.fromWindow(window), | |
child: Directionality( | |
textDirection: TextDirection.ltr, | |
child: Navigator( | |
onGenerateRoute: (RouteSettings settings) { | |
return MaterialPageRoute<void>( | |
settings: settings, | |
builder: (BuildContext context) { | |
return Material( | |
child: IndexedStack( | |
index: selectedIndex, | |
children: [ | |
Center( | |
child: Column( | |
children: [ | |
TextField(), | |
OutlineButton( | |
onPressed: () => _setIndex(1), | |
child: Text('Switch to index 1'), | |
), | |
], | |
), | |
), | |
Center( | |
child: Column( | |
children: [ | |
TextField(), | |
OutlineButton( | |
onPressed: () => _setIndex(0), | |
child: Text('Switch to index 0'), | |
), | |
], | |
), | |
), | |
], | |
), | |
); | |
}, | |
); | |
}, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chrome 98.0.4758.109 (Official Build) (arm64)
61659_indexstack.mp4