mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
215 lines
6.1 KiB
215 lines
6.1 KiB
2 years ago
|
import 'package:flutter/foundation.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
2 years ago
|
import 'package:flutter/services.dart';
|
||
2 years ago
|
|
||
|
import 'anywhere_page.dart';
|
||
2 years ago
|
import 'cascading_menu_page.dart';
|
||
2 years ago
|
import 'custom_buttons_page.dart';
|
||
2 years ago
|
import 'custom_menu_page.dart';
|
||
2 years ago
|
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;
|
||
|
});
|
||
|
}
|
||
|
|
||
2 years ago
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
// On web, disable the browser's context menu everywhere so that the custom
|
||
|
// Flutter-rendered context menu shows.
|
||
|
if (kIsWeb) {
|
||
|
BrowserContextMenu.disableContextMenu();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void dispose() {
|
||
|
if (kIsWeb) {
|
||
|
BrowserContextMenu.enableContextMenu();
|
||
|
}
|
||
|
super.dispose();
|
||
|
}
|
||
|
|
||
2 years ago
|
@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)>{
|
||
2 years ago
|
'/': (context) => MyHomePage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
AnywherePage.route: (context) =>
|
||
2 years ago
|
AnywherePage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
CustomButtonsPage.route: (context) =>
|
||
2 years ago
|
CustomButtonsPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
CustomMenuPage.route: (context) =>
|
||
|
CustomMenuPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
ReorderedButtonsPage.route: (context) =>
|
||
2 years ago
|
ReorderedButtonsPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
EmailButtonPage.route: (context) =>
|
||
2 years ago
|
EmailButtonPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
ImagePage.route: (context) =>
|
||
2 years ago
|
ImagePage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
FieldTypesPage.route: (context) =>
|
||
2 years ago
|
FieldTypesPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
FullPage.route: (context) =>
|
||
2 years ago
|
FullPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
ModifiedActionPage.route: (context) =>
|
||
2 years ago
|
ModifiedActionPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
GlobalSelectionPage.route: (context) =>
|
||
2 years ago
|
GlobalSelectionPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
DefaultValuesPage.route: (context) =>
|
||
2 years ago
|
DefaultValuesPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
CascadingMenuPage.route: (context) =>
|
||
2 years ago
|
CascadingMenuPage(onChangedPlatform: onChangedPlatform),
|
||
2 years ago
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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,
|
||
|
),
|
||
2 years ago
|
_MyListItem(
|
||
|
route: CustomMenuPage.route,
|
||
|
title: CustomMenuPage.title,
|
||
|
subtitle: CustomMenuPage.subtitle,
|
||
|
),
|
||
2 years ago
|
_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,
|
||
|
),
|
||
2 years ago
|
_MyListItem(
|
||
|
route: CascadingMenuPage.route,
|
||
|
title: CascadingMenuPage.title,
|
||
|
subtitle: CascadingMenuPage.subtitle,
|
||
|
),
|
||
2 years ago
|
_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),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|