1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 14:28:51 +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:
Justin McCandless
2022-11-08 22:42:25 -08:00
committed by GitHub
parent 070ce7303a
commit 41571eae07
150 changed files with 6405 additions and 0 deletions

View File

@@ -0,0 +1,180 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'anywhere_page.dart';
import 'custom_buttons_page.dart';
import 'default_values_page.dart';
import 'email_button_page.dart';
import 'field_types_page.dart';
import 'full_page.dart';
import 'global_selection_page.dart';
import 'image_page.dart';
import 'modified_action_page.dart';
import 'platform_selector.dart';
import 'reordered_buttons_page.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({
super.key,
});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
void onChangedPlatform(TargetPlatform platform) {
setState(() {
debugDefaultTargetPlatformOverride = platform;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Context Menu Examples',
theme: ThemeData(
primarySwatch: Colors.blue,
platform: defaultTargetPlatform,
),
initialRoute: '/',
routes: <String, Widget Function(BuildContext)>{
'/': (BuildContext context) =>
MyHomePage(onChangedPlatform: onChangedPlatform),
AnywherePage.route: (BuildContext context) =>
AnywherePage(onChangedPlatform: onChangedPlatform),
CustomButtonsPage.route: (BuildContext context) =>
CustomButtonsPage(onChangedPlatform: onChangedPlatform),
ReorderedButtonsPage.route: (BuildContext context) =>
ReorderedButtonsPage(onChangedPlatform: onChangedPlatform),
EmailButtonPage.route: (BuildContext context) =>
EmailButtonPage(onChangedPlatform: onChangedPlatform),
ImagePage.route: (BuildContext context) =>
ImagePage(onChangedPlatform: onChangedPlatform),
FieldTypesPage.route: (BuildContext context) =>
FieldTypesPage(onChangedPlatform: onChangedPlatform),
FullPage.route: (BuildContext context) =>
FullPage(onChangedPlatform: onChangedPlatform),
ModifiedActionPage.route: (BuildContext context) =>
ModifiedActionPage(onChangedPlatform: onChangedPlatform),
GlobalSelectionPage.route: (BuildContext context) =>
GlobalSelectionPage(onChangedPlatform: onChangedPlatform),
DefaultValuesPage.route: (BuildContext context) =>
DefaultValuesPage(onChangedPlatform: onChangedPlatform),
},
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({
super.key,
required this.onChangedPlatform,
});
final PlatformCallback onChangedPlatform;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Context Menu Demos'),
actions: <Widget>[
PlatformSelector(
onChangedPlatform: onChangedPlatform,
),
],
),
body: ListView(
children: const <Widget>[
_MyListItem(
route: AnywherePage.route,
title: AnywherePage.title,
subtitle: AnywherePage.subtitle,
),
_MyListItem(
route: GlobalSelectionPage.route,
title: GlobalSelectionPage.title,
subtitle: GlobalSelectionPage.subtitle,
),
_MyListItem(
route: ImagePage.route,
title: ImagePage.title,
subtitle: ImagePage.subtitle,
),
_MyListItem(
route: CustomButtonsPage.route,
title: CustomButtonsPage.title,
subtitle: CustomButtonsPage.subtitle,
),
_MyListItem(
route: EmailButtonPage.route,
title: EmailButtonPage.title,
subtitle: EmailButtonPage.subtitle,
),
_MyListItem(
route: ReorderedButtonsPage.route,
title: ReorderedButtonsPage.title,
subtitle: ReorderedButtonsPage.subtitle,
),
_MyListItem(
route: ModifiedActionPage.route,
title: ModifiedActionPage.title,
subtitle: ModifiedActionPage.subtitle,
),
_MyListItem(
route: FieldTypesPage.route,
title: FieldTypesPage.title,
subtitle: FieldTypesPage.subtitle,
),
_MyListItem(
route: DefaultValuesPage.route,
title: DefaultValuesPage.title,
subtitle: DefaultValuesPage.subtitle,
),
_MyListItem(
route: FullPage.route,
title: FullPage.title,
subtitle: FullPage.subtitle,
),
],
),
);
}
}
class _MyListItem extends StatelessWidget {
const _MyListItem({
required this.route,
required this.subtitle,
required this.title,
});
final String route;
final String subtitle;
final String title;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(route);
},
child: Card(
margin: const EdgeInsets.all(12.0),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: ListTile(
title: Text(title),
subtitle: Text(subtitle),
),
),
),
);
}
}