希望捕获图像保留在颤振应用程序的容器中

时间:2021-01-20 02:49:21

标签: android image flutter tabbar

我有三个标签。其中一个选项卡用于编辑照片页面(检索 API 中已有的图像,使用该页面中的更新按钮编辑捕获图像并将其返回到 API)。一切正常。但是用相机捕捉图像后,切换到其他选项卡并返回此选项卡(在此状态下不保存),已捕捉图像不显示,仅显示API图像。我再次捕获以保存。尽管我不保存到 API 并更改选项卡,但我想将捕获的图像保留在容器中。

This is picture of my app contain tab bar view which contain edit image tab bar

这是我的标签栏视图 dart 文件。

    var width = MediaQuery.of(context).size.width;
    final tabText = TextStyle(fontSize: width * 0.03);
    return Scaffold(
      appBar: new AppBar(
        title: new Text(
          'EDIT CLIENT',
          style: new TextStyle(color: accentColor, fontFamily: 'Dosis'),
        ),
        bottom: PreferredSize(
          preferredSize: Size(40, 40),
          child: Container(
            height: getScreenHeightRation(40.0),
            decoration: BoxDecoration(
              color: Color(0xFFF0C185),
              border: Border.all(color: Colors.grey[600]),
              //0xFFF0C185
            ),
            child: TabBar(
              indicatorPadding: EdgeInsets.symmetric(horizontal: 40),
              //isScrollable: true,
              //change here
              labelPadding: EdgeInsets.only(left: 10),
              indicatorSize: TabBarIndicatorSize.tab,
              indicatorColor: Colors.transparent,
              indicator: BoxDecoration(
                color: Color(0xFFD2A368),
              ),
              tabs: [
                Container(
                  decoration: BoxDecoration(
                      border: Border(right: BorderSide(color: Colors.grey))),
                  child: Tab(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        ImageIcon(
                          AssetImage('assets/images/icon_ext/menu.png'),
                          size: 12,
                        ),
                        SizedBox(
                          width: 5.0,
                        ),
                        Text('Customer Data',style: tabText, ),
                      ],
                    ),
                  ),
                ),
                Container(
                  decoration: BoxDecoration(
                      border: Border(right: BorderSide(color: Colors.grey))),
                  child: Tab(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        ImageIcon(
                          AssetImage('assets/images/icon_ext/image.png'),
                          size: 12,
                        ),
                        SizedBox(
                          width: 5.0,
                        ),
                        Text('Profile',style: tabText, )
                      ],
                    ),
                  ),
                ),
                Container(
                  child: Tab(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        ImageIcon(
                          AssetImage('assets/images/icon_ext/placeholder.png'),
                          size: 12,
                        ),
                        SizedBox(
                          width: 5.0,
                        ),
                        Text('Location',style: tabText, )
                      ],
                    ),
                  ),
                )
              ],
              controller: tabController,
            ),
          ),
        ),
        iconTheme: new IconThemeData(color: accentColor),
        centerTitle: true,
      ),
      body: TabBarView(
        controller: tabController,
        children: [
          EditClientInformation(
            customerNo: widget.customerNo,
            branchId: _branchId,
            defaultBranchId: _defaultBranchId,
            userId: _userId,
            systemFormatDate: _systemFormatDate,
          ),
          EditClientProfile(
            customerNo: widget.customerNo,
            branchId: _branchId,
            defaultBranchId: _defaultBranchId,
            userId: _userId,
            systemFormatDate: _systemFormatDate,
          ),
          EditClientMap(
            customerNo: widget.customerNo,
            branchId: _branchId,
            defaultBranchId: _defaultBranchId,
            userId: _userId,
            systemFormatDate: _systemFormatDate,
          ),
        ],
      ),
    );
  }

这是捕获图像选项卡。

  Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Stack(
                    children: [
                      Container(
                        width: 300.0,
                        height: 170.0,
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(20)),
                          border:
                              Border.all(width: 1, style: BorderStyle.solid),
                        ),
                        child: Center(
                          child: Container(
                            width: 170.0,
                            height: double.infinity,
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.only(
                                  topRight: Radius.circular(20),
                                  topLeft: Radius.circular(10),
                                  bottomLeft: Radius.circular(10),
                                  bottomRight: Radius.circular(10)),
                              //border: Border.all(width: 1, style: BorderStyle.solid),
                              image: DecorationImage(
                                image: _profileCaptImg == ""
                                    ? NetworkImage(_profileImg)
                                    : FileImage(profile),
                                fit: BoxFit.cover,
                              ),
                            ),
                          ),
                        ),
                      ),
                      Positioned(
                        right: 62.0,
                        top: 0.0,
                        child: _profileCaptImg != ''
                            ? GestureDetector(
                                onTap: () {
                                  setState(() {
                                    profile = null;
                                    _profileCaptImg = '';
                                  });
                                },
                                child: Container(
                                  width: 20.0,
                                  height: 20.0,
                                  child: Icon(
                                    Icons.close,
                                    color: Colors.white,
                                    size: 20.0,
                                  ),
                                  decoration: BoxDecoration(
                                    shape: BoxShape.circle,
                                    color: Colors.black,
                                  ),
                                ),
                              )
                            : Container(),
                      ),
                    ],
                  ),
                  Container(
                      width: 50.0,
                      height: 50.0,
                      child: FloatingActionButton(
                        onPressed: profileImgPicker,
                        heroTag: null,
                        child: new Icon(Icons.camera_alt),
                      )),
                ],
              ),

1 个答案:

答案 0 :(得分:0)

试试这个解决方案:

/// Add with AutomaticKeepAliveClientMixin:
class _YourWidgetState extends State<YourWidget> with AutomaticKeepAliveClientMixin {

/// Add these 2 lines:
  @override
  bool get wantKeepAlive => true;

/// Add super.build(context) to your build method
  @override
  Widget build(BuildContext context) {
    super.build(context);
    
    return YourWidgets();
  }

}