bitsdojo_window icon indicating copy to clipboard operation
bitsdojo_window copied to clipboard

state changing / new rendering after maximize Window

Open snorliman opened this issue 4 years ago • 2 comments
trafficstars

When I make full screen from normal size of app, the state, that hold bool "loading", is restarted, like this are new rendering. There is a option to avoid this?

snorliman avatar Sep 13 '21 11:09 snorliman

Hi there,

Do you have an example what you mean by the state that hold bool "loading"? Maybe sample repository so that I can better understand your question?

bitsdojo avatar Sep 13 '21 11:09 bitsdojo

The bool that control "loading" state was not the issue but something similar. This is Subsection Card, on click Visibility show/hide content, when i have opened some Card and click maximize to fullscreen, the Card hide the content and that is behavior that I try to avoid. This code of SubSectionCard:

import 'package:app_project/animation/animation.dart';
import 'package:app_project/controler/panel_notifire.dart';
import 'package:app_project/controler/search_by_number_notifire.dart';
import 'package:app_project/custom_subcard/avaiable_products_custom.dart';
import 'package:app_project/custom_subcard/calibration_custom.dart';
import 'package:app_project/custom_subcard/delivery_custom.dart';
import 'package:app_project/custom_subcard/finish_date_custom.dart';
import 'package:app_project/custom_subcard/orders_custom.dart';
import 'package:app_project/custom_subcard/pricing_custom.dart';
import 'package:app_project/custom_subcard/repair_custom.dart';
import 'package:app_project/custom_subcard/where_is_product_custom.dart';
import 'package:app_project/style/style.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SubSectionCard extends StatefulWidget {
  final int id;
  final String name;
  final String tags;
  final String textRead;
  final String textProblem;
  final String textComment;
  final bool customContent;

  SubSectionCard(
      {required Key key,
      required this.id,
      required this.name,
      required this.tags,
      required this.textRead,
      required this.textProblem,
      required this.textComment,
      required this.customContent})
      : super(key: key);
  @override
  _SubSectionCardState createState() => _SubSectionCardState(
      this.id,
      this.name,
      this.tags,
      this.textRead,
      this.textProblem,
      this.textComment,
      this.customContent);
}

class _SubSectionCardState extends State<SubSectionCard> {
  Tween<double> scaleTween = Tween<double>(begin: subCardScale, end: 1);
  bool isVisibleDetail = false;
  bool isClicked = false;
  final int id;
  final String name;
  final String tags;
  final String? textRead;
  final String? textProblem;
  final String? textComment;
  final bool customContent;
  _SubSectionCardState(this.id, this.name, this.tags, this.textRead,
      this.textProblem, this.textComment, this.customContent);
  Widget showCustomContent(bool isSelected) {
    if (isSelected) {
      switch (id) {
        case 29:
          return PricingCustom();

        case 32:
          return RepairCustom();

        case 5:
          return CalibrationCustom();

        case 4:
          return WhereIsProductCustom();

        case 62:
          return FinishDateCustom();

        case 45:
          return DeliveryCustom();

        case 69:
          return AvaiableProductsCustom();

        case 64:
          return OrdersCustom();

        default:
          return Container();
      }
    } else {
      return Container();
    }
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    PanelNotifire panelNotifire = Provider.of<PanelNotifire>(context);
    SearchByNumberNotifire searchByNumberNotifire =
        Provider.of<SearchByNumberNotifire>(context);
    if (panelNotifire.panelOpenAll) {
      if (isClicked) {
        isVisibleDetail = true;
      } else {
        isVisibleDetail = !isVisibleDetail;
      }
    } else {
      if (isClicked) {
        isVisibleDetail = !isVisibleDetail;
      } else {
        isVisibleDetail = false;
      }
    }

    final screenWidth = MediaQuery.of(context).size.width;
    return Container(
        margin: const EdgeInsets.only(left: 30, right: 30),
        padding: const EdgeInsets.all(4.0),
        child: Column(
          children: [
            Container(
              width: screenWidth * 0.9,
              child: ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    shape: const BeveledRectangleBorder(
                        borderRadius: BorderRadius.all(Radius.circular(7))),
                    primary: primaryColor,
                    elevation: 2,
                  ),
                  onPressed: () {
                    setState(() {
                      isClicked = !isClicked;
                    });
                  },
                  child: Padding(
                    padding: const EdgeInsets.all(7.0),
                    child: Text(
                      name,
                      style: const TextStyle(fontSize: mediumFont),
                    ),
                  )),
            ),
            Visibility(
              maintainState: true,
              visible: isVisibleDetail,
              child: TweenAnimationBuilder(
                tween: scaleTween,
                duration: Duration(milliseconds: subCardDuration),
                builder: (context, double scale, child) {
                  return Transform.scale(
                    scale: scale,
                    child: child,
                  );
                },
                child: Container(
                  width: screenWidth * 0.907,
                  child: (!customContent)
                      ? Column(
                          children: [
                            textComment != ""
                                ? Card(
                                    elevation: 9,
                                    color: cardAtettionColor,
                                    child: Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: ListTile(
                                        title: Text(
                                          textComment ?? "",
                                          style: const TextStyle(
                                              fontWeight: FontWeight.bold),
                                        ),
                                        subtitle: Text('Uwagi'),
                                      ),
                                    ),
                                  )
                                : Container(
                                    height: 3,
                                  ),
                            textRead != ""
                                ? Card(
                                    elevation: 9,
                                    color: cardReadToClientColor,
                                    child: Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: ListTile(
                                        title: Text(textRead ?? "",
                                            style: const TextStyle(
                                                fontWeight: FontWeight.bold)),
                                        subtitle: Text('Przeczytaj Klientowi'),
                                      ),
                                    ),
                                  )
                                : Container(
                                    height: 3,
                                  ),
                            textProblem != ""
                                ? Card(
                                    elevation: 9,
                                    color: cardInCaseOfProblemsColor,
                                    child: Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: ListTile(
                                        title: Text(
                                          textProblem ?? "",
                                          style: const TextStyle(
                                              fontWeight: FontWeight.bold),
                                        ),
                                        subtitle: Text('W przypadku problemów'),
                                      ),
                                    ),
                                  )
                                : Container(
                                    height: 3,
                                  ),
                          ],
                        )
                      : showCustomContent(searchByNumberNotifire.isSelected),
                ),
              ),
            ),
          ],
        ));
  }
}

SubCard is in MyHomePage build function looks like that:

 @override
  Widget build(BuildContext context) {
    PanelNotifire panelNotifire = Provider.of<PanelNotifire>(context);
    return Center(
      child: WindowBorder(
        color: Colors.white,
        width: 1.0,
        child: Scaffold(
          drawer: NavBar((int dataId, data) {
            setState(() {
              selectedIndex = dataId;
              pickedWidget = getPickedWidget(data);
            });
          }, listOfCategories),
          appBar: AppBar(
            title: const Text('page'),
            bottom: PreferredSize(
              preferredSize: Size(600, 15),
              child: WindowTitleBarBox(
                child: MoveWindow(),
              ),
            ),
            toolbarHeight: 57.00,
            elevation: 10,
            actions: [
              WindowTitleBarBox(
                child: Row(
                  children: [MoveWindow(), WindowButtons()],
                ),
              ),
              Hero(
                  tag: _heroPhone,
                  child: Material(
                      color: primaryColor,
                      child: IconButton(
                          onPressed: () {
                            Navigator.of(context).push(HeroDialogRoute(
                                builder: (context) =>
                                    Center(child: _Phone(key: UniqueKey()))));
                          },
                          icon: Icon(Icons.phone)))),
            ],
          ),
          body: WindowBorder(
            color: Colors.white,
            width: 0.03,
            child: SingleChildScrollView(
              child: Container(
                height: MediaQuery.of(context).size.height,
                width: MediaQuery.of(context).size.width,
                color: containerBGColor,
                child: Column(children: [
                  Visibility(
                      visible: panelNotifire.showSearchDetail,
                      child: showGoodSearchPanel(panelNotifire)),
                  PanelBar(),
                  Expanded(
                    child: pickedWidget.subcategories.length != 0
                        ? ListView.builder(
                            itemCount: pickedWidget.subcategories.length,
                            itemBuilder: (context, int index) {
                              Subcategory subCard =
                                  pickedWidget.subcategories[index];

                              return SubSectionCard(
                                  key: UniqueKey(),
                                  id: subCard.id,
                                  name: subCard.name,
                                  tags: subCard.tags ?? "",
                                  textRead: subCard.textRead ?? "",
                                  textProblem: subCard.textProblem ?? "",
                                  textComment: subCard.textComment ?? "",
                                  customContent: subCard.customContent);
                            })
                        : Container(
                            child: Center(child: CircularProgressIndicator())),
                  )
                ]),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

The Provider was used here to navigate the app:

class PanelNotifire extends ChangeNotifier {
  bool _panelOpenAll = false;
  bool _showSearchDetail = false;
  String _navigation = "panel";
  bool get panelOpenAll => _panelOpenAll;
  bool get showSearchDetail => _showSearchDetail;

  String get navigation => _navigation;

  closeAll() {
    _panelOpenAll = false;
    notifyListeners();
  }

  openAll() {
    _panelOpenAll = true;
    notifyListeners();
  }

  toggleShowSearchDetail() {
    _showSearchDetail = !_showSearchDetail;
    notifyListeners();
  }

  onMarkItem() {
    _navigation = "markedItem";
    notifyListeners();
    notifyListeners();
  }

  goToPanel() {
    _navigation = "panel";
    notifyListeners();
  }

  searchByNumber() {
    _navigation = "searchByNumber";
    notifyListeners();
  }

  searchByCompany() {
    _navigation = "searchByCompany";
    notifyListeners();
  }

  searchByNumberReport() {
    _navigation = "searchByNumberReport";
    notifyListeners();
  }

  searchByHistory() {
    _navigation = "searchByHistory";
    notifyListeners();
  }
}

snorliman avatar Sep 13 '21 12:09 snorliman