0

我正在开发一个具有多个屏幕的应用程序。摄像头图像捕捉屏幕永远不会被主屏幕直接调用,而不是子屏幕。尽管当我将相机选择器代码放入主文件并执行时,它可以完美地作为一个单独的颤振项目工作。但是,当我通过使用有状态小部件类并通过 Navigator 推送调用它来执行相同操作时,它只是没有响应。相机开口部分。

调用相机屏幕的屏幕代码

import 'package:carryon/luggageupdatepage.dart';
import 'package:carryon/scannerscreen.dart';
import 'package:flutter/material.dart';
import 'allvalues.dart';
import 'login_screen.dart';
import 'welcome_screen.dart';
import 'auth.dart';
class DetailsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Detailspage();
  }
}


class Detailspage extends StatefulWidget {
  @override
  _DetailspageState createState() => _DetailspageState();
}

class _DetailspageState extends State<Detailspage>
    with TickerProviderStateMixin{
  final AuthServices _auth=AuthServices();
  void _showDialog() {
    // flutter defined function
    showDialog(
      context: context,
      builder: (BuildContext context) {
        // return object of type Dialog
        return AlertDialog(
          title: Text("Invalid PNR",
            style: TextStyle(fontSize: 14),),
          content: Text(
            "Please neter a valid PNR number.",
            style: TextStyle(fontSize: 12,),),
          actions: <Widget>[
            // usually buttons at the bottom of the dialog
            new FlatButton(
              child: new Text("Close"),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }
  AnimationController controller;
  Animation<double> animation;
  @override
  initState() {
    super.initState();
    controller = AnimationController(
        duration: const Duration(seconds: 3), vsync: this);
    animation = CurvedAnimation(parent: controller, curve: Curves.easeIn);
    controller.forward();
  }
  @override
  Widget build(BuildContext context) {
    return FadeTransition(
      opacity: animation,
      child: Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor: Background_Color,
        appBar: AppBar(
          actions: <Widget>[
            FlatButton.icon(onPressed: ()async{
              await _auth.signOut();
              Navigator.push(context,
                MaterialPageRoute(
                    builder: (context)=>CarryOn()),);
            },
                icon: Icon(Icons.perm_identity), label: Text('Logout'))
          ],
          title: Text(
            'Flight CheckIn',
            style: LoginScreenTextStyle.copyWith(fontSize: 20),
          ),

        ),
        body: Column(
          children: <Widget>[
            SizedBox(height: 30,),
            Container(
              width: double.infinity,
              color: Colors.green,
              child: Text(
                'Your Flight ${userdetails.FlightName} from ${userdetails.Departure_Destination} to ${userdetails.Arrival_Destination} on ${userdetails.Departure_Date} is on time. Kindly report one hour prior to boarding time.',
                style: TextStyle(
                  fontSize: 15,
                  color: Colors.black,
                ),
              ),
            ),
            SizedBox(height: 100,),
            Row(
              children: <Widget>[
                SizedBox(width: 60,),
                Image.asset('assets/images/flighticon.png',height: 100,width: 100,),
              SizedBox(width:20),
                Container(
                  height: 100,
                  child: Column(
                    children: <Widget>[
                      Container(
                        height: 20,
                        color: Colors.white,
                        child: Text(
                          '${userdetails.Departure_Destination}',
                          style: TextStyle(color: Colors.black),
                        ),
                      ),
                      SizedBox(height: 20,),
                      Container(
                        height: 20,
                        color: Background_Color,
                        child: Text(
                          '${userdetails.Departure_Time}hrs-${userdetails.Arrival_Time}hrs',
                          style: TextStyle(color: Colors.grey),
                        ),
                      ),
                      SizedBox(height: 20,),
                      Container(
                        height: 20,
                        color: Colors.white,
                        child: Text(
                          '${userdetails.Arrival_Destination}',
                          style: TextStyle(color: Colors.black),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
            SizedBox(height: 80,),
            Container(
              height: 50,width:250,
              child: DecoratedBox(
                decoration:ShapeDecoration(shape:roundedrectangle, color:Button_Color),
                child: OutlineButton(
                  color:Button_Color,
                  borderSide: BorderSide(color:Colors.white,),
                  shape: roundedrectangle,

                  child: Center(child: Text('My Luggage Status')),
                  onPressed: ()
                  {
                    Navigator.push(context,
                      MaterialPageRoute(
                          builder: (context)=>LuggageUpdates()),);

                  },
                ),

              ),
            ),
            SizedBox(height: 30,),
            Container(
              height: 50,width:250,
              child: DecoratedBox(
                decoration:ShapeDecoration(shape:roundedrectangle, color:Button_Color),
                child: OutlineButton(
                  color:Button_Color,
                  borderSide: BorderSide(color:Colors.white,),
                  shape: roundedrectangle,

                  child: Center(child: Text('Repeat CheckIn')),
                  onPressed: ()
                  {
                    Navigator.push(context,
                      MaterialPageRoute(
                          builder: (context)=>MyApp()),);

                  },
                ),

              ),
            ),

          ],
        ),
      ),
    );
  }
}

我用来为相机屏幕执行的代码:

import 'package:flutter/material.dart';
import 'dart:io';
import 'package:image_picker/image_picker.dart';


class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  File _image;
  Future getImage(bool isCamera)
  async{
    File image;
    if(isCamera)
    {
      image=await ImagePicker.pickImage(source: ImageSource.camera);
      print('camera chale to sahi');

    }
    else
      image=await ImagePicker.pickImage(source: ImageSource.gallery);
    setState(() {
      _image=image;
    });
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Image Pick Demo',),
        ),
        body: Column(
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.insert_drive_file),
              onPressed:(){
                getImage(false);
              },
            ),
            SizedBox(height: 10,),
            IconButton(
              icon: Icon(Icons.camera_alt),
              onPressed: (){getImage(true);},
            ),
            _image==null?Container():Image.file(_image,height: 300,width: 300,),
          ],
        ),
      ),
    );
  }
}

当直接由 main.dart 运行时,完全相同的代码可以工作,所以我在调用 camera_screen.dart 文件时犯了一些错误。

4

0 回答 0