Skip to content

Instantly share code, notes, and snippets.

@anmolseth06
Created December 28, 2020 16:46
Show Gist options
  • Save anmolseth06/db5d91c5990fa43a7b40d6cc66f59f81 to your computer and use it in GitHub Desktop.
Save anmolseth06/db5d91c5990fa43a7b40d6cc66f59f81 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:quick_actions/quick_actions.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Quick Actions Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
QuickActions quickActions = QuickActions();
_navigate(Widget screen) {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => screen));
}
@override
void initState() {
super.initState();
quickActions.initialize((String shortcutType) {
switch (shortcutType) {
case 'cart_page':
return _navigate(CartPage(
title: shortcutType,
));
case 'order_page':
return _navigate(OrderPage(
title: shortcutType,
));
case 'notification_page':
return _navigate(NotificationPage(
title: shortcutType,
));
case 'place_order':
return _navigate(PlaceOrder(
title: shortcutType,
));
default:
return MaterialPageRoute(builder: (_) {
return Scaffold(
body: Center(
child: Text('No Page defined for $shortcutType'),
),
);
});
}
});
quickActions.setShortcutItems(<ShortcutItem>[
ShortcutItem(
type: 'cart_page',
localizedTitle: 'Cart Page',
),
ShortcutItem(
type: 'order_page',
localizedTitle: 'Order Page',
),
ShortcutItem(
type: 'notification_page',
localizedTitle: 'Notification Page',
),
ShortcutItem(
type: 'place_order',
localizedTitle: 'Place Order',
),
]);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Homepage'),
),
body: const Center(
child: Text('Welcome to homepage'),
),
);
}
}
class CartPage extends StatelessWidget {
final String title;
CartPage({this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Text(title),
),
);
}
}
class OrderPage extends StatelessWidget {
final String title;
OrderPage({this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Text(title),
),
);
}
}
class PlaceOrder extends StatelessWidget {
final String title;
PlaceOrder({this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Text(title),
),
);
}
}
class NotificationPage extends StatelessWidget {
final String title;
NotificationPage({this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Text(title),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment