如何处理释放构建apk上的反击

时间:2018-04-22 14:33:36

标签: dart flutter onbackpressed

我不知所措,我试图在颤动中处理新闻事件。它的工作原理只有调试版本,当我尝试发布版本后退按下事件没有触发我知道什么错误。任何帮助将不胜感激,谢谢你。

我尝试了WidgetsBindingObserveronWillPop这两项工作仅适用于调试apk。当使用flutter build apk cmd(在文件夹build \ app \ outputs \ apk \ release下)获取发布版本时,不会触发新闻事件。

    import 'dart:async';
import 'dart:io';

import 'package:cryptocurrency_app/data/crypto_data.dart';
import 'package:cryptocurrency_app/home/home_presenter.dart';
import 'package:flutter/material.dart';

class HomeList extends StatefulWidget {
  HomeList({ Key key }) : super(key: key);
  @override
  _HomeListState createState() => new _HomeListState();
}

class _HomeListState extends State<HomeList>  {
  final key = new GlobalKey<ScaffoldState>();
  _HomeListState() {

  }

  @override
  void initState() {
    super.initState();
    // WidgetsBinding.instance.addObserver(this);

  }

/*
  @override
  void dispose() {
   // WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }*/

  Future<bool> _onWillPop() {
    return showDialog(
        context: context,
        child: new AlertDialog(
          title: new Text('Exit'),
          content: new Text('Are you sure you want to exit ?'),
          actions: <Widget>[
            new FlatButton(
              onPressed: () => Navigator.of(context).pop(true),
              child: new Text('Yes',
                  style: new TextStyle(color: Colors.black)),
            ),
            new FlatButton(
              onPressed: () => Navigator.of(context).pop(false),
              child: new Text('No',
                  style: new TextStyle(color: Colors.black)),
            ),
          ],
        ),
      );
  }

  @override
  Widget build(BuildContext context) {
    var widget;
   widget = new WillPopScope(
          onWillPop: _onWillPop,

          child: new Scaffold(
            key: key,
            appBar: buildBar(context),
            body: new Center(
                child: new Padding(
                    padding: const EdgeInsets.only(left: 16.0, right: 16.0),
                    child: new CircularProgressIndicator()
                )
            ),
          ));
    }
    return widget;
  }

  Widget buildBar(BuildContext context) {
    return new AppBar(
      leading: new IconButton(
        icon: const Icon(Icons.search),
        color: Theme
            .of(context)
            .accentColor,
        onPressed: _handleSearchStart,
        tooltip: 'Search',
      ),
      title: new Text("Crypto Live Rates",
        style: new TextStyle(color: Colors.white),
      ),
    );
  }



}

0 个答案:

没有答案