mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 06:18:49 +00:00
Custom context menu example (#1463)
* flutter create * Copied in from 'contextual-menu-examples' repo * Works again with the latest updates to the branch * Clean up anywhere example * Clean up other examples * Add to CI * Updated with release version of context menus, and added platform switcher * Generated files * Home icon on your original platform * Remove web_dashboard from ci, not sure why that change was there... * Add context_menu to beta channel, but commented out, for the future * +x permissions on the master script, which I may have accidentally changed before? * Actual bash comment * dart format * Natural default platform' * A working test, for the email page * Import order fix * Test some pages * More tests * dart format
This commit is contained in:
committed by
GitHub
parent
070ce7303a
commit
41571eae07
61
experimental/context_menus/lib/platform_selector.dart
Normal file
61
experimental/context_menus/lib/platform_selector.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
typedef PlatformCallback = void Function(TargetPlatform platform);
|
||||
|
||||
class PlatformSelector extends StatefulWidget {
|
||||
const PlatformSelector({
|
||||
super.key,
|
||||
required this.onChangedPlatform,
|
||||
});
|
||||
|
||||
final PlatformCallback onChangedPlatform;
|
||||
|
||||
@override
|
||||
State<PlatformSelector> createState() => _PlatformSelectorState();
|
||||
}
|
||||
|
||||
class _PlatformSelectorState extends State<PlatformSelector> {
|
||||
static const int targetPlatformStringLength = 15; // 'TargetPlatform.'.length
|
||||
|
||||
static String _platformToString(TargetPlatform platform) {
|
||||
return platform.toString().substring(targetPlatformStringLength);
|
||||
}
|
||||
|
||||
final TargetPlatform originaPlatform = defaultTargetPlatform;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: 160.0,
|
||||
child: DropdownButton<TargetPlatform>(
|
||||
value: defaultTargetPlatform,
|
||||
icon: const Icon(Icons.arrow_downward),
|
||||
elevation: 16,
|
||||
onChanged: (TargetPlatform? value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.onChangedPlatform(value);
|
||||
setState(() {});
|
||||
},
|
||||
items: TargetPlatform.values.map((TargetPlatform platform) {
|
||||
return DropdownMenuItem<TargetPlatform>(
|
||||
value: platform,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
if (platform == originaPlatform)
|
||||
const Icon(
|
||||
Icons.home,
|
||||
color: Color(0xff616161),
|
||||
),
|
||||
Text(_platformToString(platform)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user