1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 06:18:49 +00:00
Files
samples/experimental/context_menus/lib/platform_selector.dart
Miguel Beltran 18ead8138a Enable Material 3 on context_menus (#1948)
Enable Material 3

#### Before Material 3

<img width="912" alt="Screenshot 2023-07-20 at 13 53 16"
src="https://github.com/flutter/samples/assets/2494376/f2686f50-f08b-4810-a35b-62b7247a1327">
<img width="912" alt="Screenshot 2023-07-20 at 13 53 08"
src="https://github.com/flutter/samples/assets/2494376/7b3882bd-ba32-4a29-b262-482b2af028a5">

#### With Material 3

<img width="912" alt="Screenshot 2023-07-20 at 13 54 12"
src="https://github.com/flutter/samples/assets/2494376/15cb182d-8191-4afa-953b-cc037944ecee">
<img width="912" alt="Screenshot 2023-07-20 at 13 54 06"
src="https://github.com/flutter/samples/assets/2494376/46151882-309f-4b7d-a2c3-a3700f6b8c17">


## Pre-launch Checklist

- [ ] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [ ] I signed the [CLA].
- [ ] I read the [Contributors Guide].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-devrel
channel on [Discord].

<!-- Links -->
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[CLA]: https://cla.developers.google.com/
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[Contributors Guide]:
https://github.com/flutter/samples/blob/main/CONTRIBUTING.md

---------

Co-authored-by: Brett Morgan <brettmorgan@google.com>
2023-07-22 09:57:10 +10:00

62 lines
1.6 KiB
Dart

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: 170.0,
child: DropdownButton<TargetPlatform>(
value: defaultTargetPlatform,
icon: const Icon(Icons.arrow_downward),
elevation: 16,
onChanged: (value) {
if (value == null) {
return;
}
widget.onChangedPlatform(value);
setState(() {});
},
items: TargetPlatform.values.map((platform) {
return DropdownMenuItem<TargetPlatform>(
value: platform,
child: Row(
children: <Widget>[
if (platform == originaPlatform)
const Icon(
Icons.home,
color: Color(0xff616161),
),
Text(_platformToString(platform)),
],
),
);
}).toList(),
),
);
}
}