Skip to content

Instantly share code, notes, and snippets.

@Piinks
Last active April 26, 2019 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Piinks/35fb0d304642c97db0737e2c23830823 to your computer and use it in GitHub Desktop.
Save Piinks/35fb0d304642c97db0737e2c23830823 to your computer and use it in GitHub Desktop.
Reproduces DropdownButton menu location being off
import 'package:flutter/material.dart';
class CustomMaterialPageRoute<T> extends MaterialPageRoute<T> {
CustomMaterialPageRoute({
@required WidgetBuilder builder,
RouteSettings settings,
bool maintainState = true,
bool fullscreenDialog = false,
}) : super(
builder: builder,
maintainState: maintainState,
settings: settings,
fullscreenDialog: fullscreenDialog,
);
@override
Widget buildTransitions(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child
) => child;
}
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Material(
child: Center( // <- This makes the difference, i.e. change to a Scaffold, no issue.
child: MyStatefulWidget()
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
String _value;
Widget build(BuildContext context) {
return ConstrainedBox(
// Changing the constraints here results in the dropdown menu showing up in different places
constraints: new BoxConstraints.tight(const Size(300.0, 600.0)),
child: Navigator(onGenerateRoute: (RouteSettings s) {
return CustomMaterialPageRoute<void>(builder: (BuildContext context) {
return Center(child:DropdownButton<String>(
hint: Text('Select'),
value: _value,
onChanged: (String newValue) {
setState(() {
_value = newValue;
});
},
items: <String>['One', 'Two', 'Three']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),);
});
}),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment