Skip to content

Instantly share code, notes, and snippets.

@slightfoot
Created June 30, 2018 14:15
Show Gist options
  • Save slightfoot/660a002f2fe0a4699f29493802cdac4c to your computer and use it in GitHub Desktop.
Save slightfoot/660a002f2fe0a4699f29493802cdac4c to your computer and use it in GitHub Desktop.
Example of using defaultTargetPlatform to change the entire widget tree based on platform.
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
//runApp(IOSApp());
//runApp(AndroidApp());
runApp(defaultTargetPlatform == TargetPlatform.iOS ? IOSApp() : AndroidApp());
}
class IOSApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primaryColor: Colors.grey[100]),
home: Material(
child: CupertinoPageScaffold(
backgroundColor: CupertinoColors.lightBackgroundGray,
navigationBar: CupertinoNavigationBar(middle: Text('Example')),
child: ListView.builder(itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () => {},
child: Container(
margin: const EdgeInsets.symmetric(vertical: 8.0),
padding: const EdgeInsets.symmetric(horizontal: 10.0),
height: 50.0,
decoration: const BoxDecoration(
color: CupertinoColors.white,
border: Border(
bottom: BorderSide(color: Colors.black26, width: 0.0)
),
),
child: Row(
children: <Widget>[
Expanded(
child: Text('Item $index',
style: const TextStyle(fontSize: 16.0, color: Colors.black),
),
),
Icon(CupertinoIcons.right_chevron,
color: CupertinoColors.inactiveGray,
),
],
),
),
);
}),
),
),
);
}
}
class AndroidApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primaryColor: Colors.grey[100]),
home: Scaffold(
backgroundColor: Colors.grey[200],
appBar: AppBar(title: Text('Example')),
body: ListView.builder(itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () => {},
child: Card(
margin: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
color: CupertinoColors.white,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
height: 56.0,
child: Row(
children: <Widget>[
new Expanded(
child: new Text('Item $index',
style: new TextStyle(fontSize: 16.0, color: Colors.black),
),
),
new Icon(Icons.chevron_right,
color: Colors.grey,
),
],
),
),
),
);
}),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment