Skip to content

Instantly share code, notes, and snippets.

@huynguyennovem
Created March 8, 2022 13:10
Show Gist options
  • Save huynguyennovem/3cfca809ab417afd78488dc632033f68 to your computer and use it in GitHub Desktop.
Save huynguyennovem/3cfca809ab417afd78488dc632033f68 to your computer and use it in GitHub Desktop.
IndexedStack lose focused when switching between index
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'),
),
],
),
),
],
),
);
},
);
},
),
),
),
);
}
}
@huynguyennovem
Copy link
Author

  • Issue: flutter/flutter#61659
  • Flutter version: 2.10.3
  • Tested device: Mac OS Big Sur 11.6 M1
    Chrome 98.0.4758.109 (Official Build) (arm64)
  • Replicable: No
61659_indexstack.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment