Flutter端代碼

新建一個頁面FirstScreen.dart
main.dart改動代碼app

導入
import 'dart:ui' as ui;
import 'package:flutter_module/FirstScreen.dart';
1
2
修改
//void main() => runApp(MyApp());
void main() => runApp(_widgetForRoute(ui.window.defaultRouteName));less

Widget _widgetForRoute(String route) {
switch (route) {
case 'myApp':
return MyApp();
default:
return MaterialApp(
home: Center(
child: Text('沒找到'),
),
);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
增長一個函數跳轉:FirstScreen.dartasync

class _MyHomePageState extends State<MyHomePage> {
......
Future<void> _goOCPage(BuildContext context) async {
print('我要去Flutter 的下一個頁面了');
Navigator.push(context, MaterialPageRoute(builder: (context){
return new FirstScreen();
}));
}
......
}
1
2
3
4
5
6
7
8
9
10
在body的{} 中添加一個文本和按鈕FlatButton用於跳轉到FirstScreen.dartide

Text(
'自我介紹,我是flutter頁面',
),函數

FlatButton(
child: Text("去下一個Flutter頁面"),
textColor: Colors.blue,
onPressed: (){
_goOCPage(context);
},
),
1
2
3
4
5
6
7
8
9
10
11
FirstScreen.dart 的所有代碼ui

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';orm

class FirstScreen extends StatelessWidget {
static const platform = const MethodChannel('samples.flutter.dev/battery');get

Future<void> _goOCPage() async {
print('我要去OC 頁面了');
String batteryLevel;
try {
final int result = await platform.invokeMethod('getBatteryLevel');
batteryLevel = 'Battery level at $result % .';
} on PlatformException catch (e) {
batteryLevel = "Failed to get battery level: '${e.message}'.";
}it

print('調用了$batteryLevel');
}io

Future<void> _goSomePage() async {
print('我要去導航的指定頁面了');
String batteryLevel;
try {
final int result = await platform.invokeMethod('backToNavigatorIndex',[1]);
batteryLevel = 'backSmoePahe $result % .';
} on PlatformException catch (e) {
batteryLevel = "Failed to backSmoePahe: '${e.message}'.";
}

print('back$batteryLevel');
}

@override
Widget build(BuildContext context) {

Future<dynamic> _handler(MethodCall methodCall) {
if ("passArgusToFlutter" == methodCall.method) {
print('methodCall-arguments:${methodCall.arguments}');
}
return Future.value(123);
}
platform..setMethodCallHandler(_handler);

return Scaffold(
appBar: AppBar(
title: Text('FirstScreen 頁面'),
),
body: Center(
child: Column(

mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'自我介紹,我是flutter頁面',
),

FlatButton(
child: Text("backLastPage"),
textColor: Colors.blue,
onPressed: (){
Navigator.pop(context);
},
),

FlatButton(
child: Text("goOCPage"),
textColor: Colors.blue,
onPressed: (){
_goOCPage();
},
),

FlatButton(
child: Text("backToSomePage"),
textColor: Colors.blue,
onPressed: (http://www.amjmh.com/v/BIBRGZ_558768/){
_goSomePage();
},
),

], ), ), ); }}---------------------

相關文章
相關標籤/搜索