zoukankan      html  css  js  c++  java
  • Flutter端代码

    新建一个页面FirstScreen.dart
    main.dart改动代码

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

    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.dart

    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.dart

    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 的全部代码

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

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

    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}'.";
    }

    print('调用了$batteryLevel');
    }

    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();
    },
    ),

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

  • 相关阅读:
    用户体验
    jsp ini 配置文件
    Highcharts 图表
    简单游戏服务器
    js 数据操作
    jquery 导航
    as3.0 删除子元件
    java float 保留二位小数
    局域网ip
    SWFUpload
  • 原文地址:https://www.cnblogs.com/ly570/p/11295923.html
Copyright © 2011-2022 走看看