从另一个文件返回main.dart中的类

时间:2019-12-26 08:55:34

标签: flutter dart

我有两个文件。 main.dart arview.dart

arview.dart中,有用户动作触发了回调,我想从回调内部回到main.dart

arview.dart

class ArViewState extends State<ArViewWidget> with WidgetsBindingObserver {
.
.
.
    Future<void> onArchitectWidgetCreated() async {
        this.architectWidget.setJSONObjectReceivedCallback((jsonObjectReceived) {
        // I want to go back to the TopPage class in main.dart here.
        // however how can I do that?? my code is like this below.

            return Navigator.pushReplacement(context,
            NoAnimationMaterialPageRoute(
                builder: (context) => TopPage()));

main.dart

import arview.dart;

class TopPage extends StatefulWidget {
  TopPage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _TopPageState createState() => _TopPageState();
}

class _TopPageState extends State<TopPage> {
  Widget aboutButton(num){
    return Expanded(
      child:FlatButton(
        padding:EdgeInsets.only(bottom:10,right:5,left:5,top:10),
        child:  Image.asset("mybtn.png");
      ),
    );
  }

1 个答案:

答案 0 :(得分:0)

使用import time import traceback import requests from requests.auth import HTTPDigestAuth print ("Dahua-downloader started") time.sleep(1) # DVR Param dvrhost = '10.1.1.1' channel = '1' authusername = '1111' authpassword = '1111' downyear = '2019' downmonth = '12' downday = '16' downhour = 6 uphour = 18 runtimer = time.time() + 36000 while downhour < uphour: if time.time() < runtimer: starttime = downyear + '-' + downmonth + '-' + downday + '%20' + str(downhour) + ':00:00' endtime = downyear + '-' + downmonth + '-' + downday + '%20' + str(downhour+1) + ':00:00' try: print("Start download file " + str(downhour)+ "-" + str(downhour+1) + "h") url = 'http://' + dvrhost + '/cgi-bin/loadfile.cgi?action=startLoad&channel=' + channel + '&subtype=0&startTime=' + starttime+ '&endTime=' + endtime r = requests.get(url,auth=HTTPDigestAuth(authusername, authpassword), timeout=(4, 10)) filerec = "/root/dvr/" + downyear + downmonth + downday + '-' + str(downhour) + ".dav" with open(filerec, 'wb') as f: f.write(r.content) # Retrieve HTTP meta-data print(r.status_code) print("Download file " + str(downhour)+ "-" + str(downhour+1) + "h complete") downhour = downhour + 1 time.sleep(5) except: print("Download file " + str(downhour)+ "-" + str(downhour+1) + "h error!") print(traceback.format_exc()) time.sleep(10) else: downhour = 100 print ("Time out!") if downhour == uphour: print ("Download files " + downyear + "-" + downmonth + "-" + downday + " comltele") 返回。

  

要返回原始路线,请更新onPressed()   SecondRoute小部件中的回调:

Navigator.pop()