1// Copyright 2017, the Flutter project authors. Please see the AUTHORS file 2// for details. All rights reserved. Use of this source code is governed by a 3// BSD-style license that can be found in the LICENSE file. 4 5import 'dart:async'; 6import 'dart:io'; 7import 'package:flutter/material.dart'; 8import 'package:flutter/services.dart'; 9 10void main() { 11 runApp(PlatformView()); 12} 13 14class PlatformView extends StatelessWidget { 15 @override 16 Widget build(BuildContext context) { 17 return MaterialApp( 18 title: 'Platform View', 19 theme: ThemeData( 20 primarySwatch: Colors.grey, 21 ), 22 home: const MyHomePage(title: 'Platform View'), 23 ); 24 } 25} 26 27class MyHomePage extends StatefulWidget { 28 const MyHomePage({Key key, this.title}) : super(key: key); 29 30 final String title; 31 32 @override 33 _MyHomePageState createState() => _MyHomePageState(); 34} 35 36class _MyHomePageState extends State<MyHomePage> { 37 static const MethodChannel _methodChannel = 38 MethodChannel('samples.flutter.io/platform_view'); 39 40 int _counter = 0; 41 42 void _incrementCounter() { 43 setState(() { 44 _counter++; 45 }); 46 } 47 48 Future<void> _launchPlatformCount() async { 49 final int platformCounter = 50 await _methodChannel.invokeMethod('switchView', _counter); 51 setState(() { 52 _counter = platformCounter; 53 }); 54 } 55 56 @override 57 Widget build(BuildContext context) => Scaffold( 58 appBar: AppBar( 59 title: Text(widget.title), 60 ), 61 body: Column( 62 crossAxisAlignment: CrossAxisAlignment.start, 63 children: <Widget>[ 64 Expanded( 65 child: Center( 66 child: Column( 67 mainAxisAlignment: MainAxisAlignment.center, 68 children: <Widget>[ 69 Text( 70 'Button tapped $_counter time${ _counter == 1 ? '' : 's' }.', 71 style: const TextStyle(fontSize: 17.0), 72 ), 73 Padding( 74 padding: const EdgeInsets.all(18.0), 75 child: RaisedButton( 76 child: Platform.isIOS 77 ? const Text('Continue in iOS view') 78 : const Text('Continue in Android view'), 79 onPressed: _launchPlatformCount), 80 ), 81 ], 82 ), 83 ), 84 ), 85 Container( 86 padding: const EdgeInsets.only(bottom: 15.0, left: 5.0), 87 child: Row( 88 children: <Widget>[ 89 Image.asset('assets/flutter-mark-square-64.png', 90 scale: 1.5), 91 const Text( 92 'Flutter', 93 style: TextStyle(fontSize: 30.0), 94 ), 95 ], 96 ), 97 ), 98 ], 99 ), 100 floatingActionButton: FloatingActionButton( 101 onPressed: _incrementCounter, 102 tooltip: 'Increment', 103 child: const Icon(Icons.add), 104 ), 105 ); 106} 107