Skip to content

Instantly share code, notes, and snippets.

@HamedTaherpour
Created October 25, 2019 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HamedTaherpour/6ee61cb8bf8c9009253eb0c75d3877d2 to your computer and use it in GitHub Desktop.
Save HamedTaherpour/6ee61cb8bf8c9009253eb0c75d3877d2 to your computer and use it in GitHub Desktop.
Flutter Cupertino Package for iOS devs
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp();
@override
Widget build(BuildContext context) {
return CupertinoApp(
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: [
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.book_solid),
title: Text('Book'),
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.eye_solid),
title: Text('Eye'),
),
],
),
tabBuilder: (context, i) {
return CupertinoTabView(
builder: (context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: (i == 0) ? Text('Book') : Text('Eye'),
),
child: Center(
child: CupertinoButton(
child: Text(
'This is tab #$i',
style: CupertinoTheme.of(context)
.textTheme
.navLargeTitleTextStyle
.copyWith(fontSize: 32),
),
onPressed: () {
Navigator.of(context).push(
CupertinoPageRoute(builder: (context) {
return DetailScreen();
}),
);
},
),
),
);
},
);
},
);
}
}
class DetailScreen extends StatefulWidget {
const DetailScreen();
@override
_DetailScreenState createState() => _DetailScreenState();
}
class _DetailScreenState extends State<DetailScreen> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Details'),
),
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CupertinoButton(
child: Text('Launch action sheet'),
onPressed: () {
showCupertinoModalPopup<int>(
context: context,
builder: (context) {
return CupertinoActionSheet(
title: Text('some choices'),
actions: [
CupertinoActionSheetAction(
child: Text('One!'),
onPressed: () {
Navigator.pop(context, 1);
},
),
CupertinoActionSheetAction(
child: Text('Two!'),
onPressed: () {
Navigator.pop(context, 2);
},
),
CupertinoActionSheetAction(
child: Text('Three!'),
onPressed: () {
Navigator.pop(context, 3);
},
),
],
);
},
);
},
)
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment