Giter Site home page Giter Site logo

Present below nothing about pip_view HOT 27 CLOSED

lslv1243 avatar lslv1243 commented on July 17, 2024
Present below nothing

from pip_view.

Comments (27)

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024 1

@lslv1243 Thanks. it would be great if you could share some examples of how to use the new RawPIPView and if it does the same as my fork, i will delete my fork happily.

from pip_view.

lslv1243 avatar lslv1243 commented on July 17, 2024

Hi, unfortunately it is not possible with the current implementation.
It would be necessary to rewrite a bit of the lib to allow any screen to become the pip without affecting the navigator.

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

I have managed to do it using your package with some modifications + Overlay.

I will submit a PR to enable/disable the bottom view now.

Edit: the version I used is not null sound, so a PR is somehow useless.

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

@HasanAlyazidi Can you please share your implementation? I am also looking for something like this. I want the floating page to be below the last opened page instead of creating a new widget. If you can share your implementation it will be great.

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

@abusaadp Check out my fork
https://github.com/HasanAlyazidi/pip_view

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

This is what i ended up doing

in main.dart

...
            return MaterialApp(
              title: 'App',
              home: LayoutBuilder(
                builder: (layoutContext, constraints) {
                  WidgetsBinding.instance?.addPostFrameCallback((_) {
                    if (alreadyAddedOverlays) {
                      return;
                    }

                    Overlay.of(context)?.insert(
                      OverlayEntry(builder: (context) => YourWidget()),
                    );

                    alreadyAddedOverlays = true;
                  });

                  return HomeScreen();
                },
              ),
              theme: ThemeData(

...

YourWidget:

class YourWidget extends StatelessWidget {
  const YourWidget({ Key? key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PIPView(
      initialCorner: PIPViewCorner.bottomLeft,
      builder: (context, isFloating) {
        return YourMinimizableAndMaximizableWidget();
      },
    );
  }
}
  • Make sure you only insert the overlay once hence using alreadyAddedOverlays variable

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

I am not able to get what you are trying to implement. Further explanation will be highly appreciated. I want the floating widget to be below my previous screen.

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

You need to insert the floating widget you want as an overlay as explained in my previous comment

it's better to create an issue in my fork and send the codes of your main.dart and floating widget, so i can understand and help if i could.

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

I am not able to create an issue in your fork. I don’t know why.

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

You may send them here

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

My main.dart code is below

import 'package:flutter/material.dart';
import 'package:pip_view/pip_view.dart';

void main() => runApp(ExampleApp());

class ExampleApp extends StatelessWidget {
  bool alreadyAddedOverlays = false;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
              title: 'App',
              home: LayoutBuilder(
                builder: (layoutContext, constraints) {
                  WidgetsBinding.instance?.addPostFrameCallback((_) {
                    if (alreadyAddedOverlays) {
                      return;
                    }

                    Overlay.of(context)?.insert(
                      OverlayEntry(builder: (context) => HomeScreen()),
                    );

                    alreadyAddedOverlays = true;
                  });

                  return FirstScreen();
                },
              ),
    );
  }
}

class FirstScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Text('This is the first page!'),
              Text('If you tap on the floating screen, it stops floating.'),
              Text('Navigation works as expected.'),
              MaterialButton(
                color: Theme.of(context).primaryColor,
                child: Text('Push to floating screen'),
                onPressed: () {
                  Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (_) => HomeScreen(),
                    ),
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return PIPView(
      builder: (context, isFloating) {
        return Scaffold(
          resizeToAvoidBottomInset: !isFloating,
          body: SafeArea(
            child: Padding(
              padding: const EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Text('This page will float!'),
                  MaterialButton(
                    color: Theme.of(context).primaryColor,
                    child: Text('Start floating!'),
                    onPressed: () {
                      PIPView.of(context)?.present();
                    },
                  ),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}

When the app starts I want to show the FirstScreen and then navigate to HomeScreen. Now when we want to float the HomeScreen it should be shown below the FirstScreen. I don't want to create the FirstScreen again, it should be shown below the previous FirstScreen. Right now it is shown below a blank screen. I want the floating screen to be shown below the previous screen.

Thank You

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

Any update?

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

Any help will be highly appreciated.

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

If you can send a demo project, that would be helpful.

Happy Eid

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

Happy Eid.
Where do you want me to send the demo project?
The main.dart file code I pasted above is used in my demo project. That is the only dart file in that project. I had replaced your main.dart with my file in the example project of your repository i.e https://github.com/HasanAlyazidi/pip_view

Thank you

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

You can check the example project from my repository https://github.com/abusaadp/pip_view
The example projects contains the main.dart with the changes suggested by you.

Thank You.

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

I will have a look. Thank you.

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

Here you go

  • you need to use Flutter 2 with null-safety

firstly, import my fork of pip_view in your pubspec.yaml

  pip_view:
    git: https://github.com/HasanAlyazidi/pip_view

Secondly, create a state manager for the floating screen, i created a static class here, but i recommend using provider package

class FloatingManager {
  static final ValueNotifier<bool> _isFloatingShown = ValueNotifier(false);

  static bool get isShown => _isFloatingShown.value;

  static void showFull() {
    _isFloatingShown.value = true;
  }

  static void minimize(BuildContext context) {
    PIPView.of(context)?.present();
  }

  static void close() {
    _isFloatingShown.value = false;
  }

  static void listen(VoidCallback callback) {
    _isFloatingShown.addListener(callback);
  }
}

here is the main.dart file

import 'package:flutter/material.dart';
import 'package:pip_view/pip_view.dart';

void main() => runApp(const ExampleApp());

class ExampleApp extends StatefulWidget {
  const ExampleApp({Key? key}) : super(key: key);

  @override
  State<ExampleApp> createState() => _ExampleAppState();
}

class _ExampleAppState extends State<ExampleApp> {
  bool alreadyAddedOverlays = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'App',
      home: LayoutBuilder(
        builder: (layoutContext, constraints) {
          WidgetsBinding.instance?.addPostFrameCallback((_) {
            if (alreadyAddedOverlays) {
              return;
            }

            // use LayoutBuilder's context (LayoutBuilder)
            Overlay.of(layoutContext)?.insert(
              OverlayEntry(builder: (context) => const HomeScreen()),
            );

            alreadyAddedOverlays = true;
          });

          return const FirstScreen();
        },
      ),
    );
  }
}

class FirstScreen extends StatelessWidget {
  const FirstScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              const Text('This is the first page!'),
              const Text(
                  'If you tap on the floating screen, it stops floating.'),
              const Text('Navigation works as expected.'),
              MaterialButton(
                color: Theme.of(context).primaryColor,
                child: const Text('Push to floating screen'),
                onPressed: () {
                  FloatingManager.showFull();
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  @override
  void initState() {
    FloatingManager.listen(() {
      setState(() {
        // do something ..
      });
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // hide floating screen when it is not shown
    if (!FloatingManager.isShown) {
      return const SizedBox.shrink();
    }

    return PIPView(
      builder: (context, isFloating) {
        return SafeArea(
          child: Padding(
            padding: const EdgeInsets.all(16),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                const Text('This page will float!'),
                MaterialButton(
                  color: Theme.of(context).primaryColor,
                  child: const Text('Start floating!'),
                  onPressed: () {
                    FloatingManager.minimize(context);
                  },
                ),
                MaterialButton(
                  color: Colors.red,
                  child: const Text('End floating!'),
                  onPressed: () {
                    FloatingManager.close();
                  },
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}

class FloatingManager {
  static final ValueNotifier<bool> _isFloatingShown = ValueNotifier(false);

  static bool get isShown => _isFloatingShown.value;

  static void showFull() {
    _isFloatingShown.value = true;
  }

  static void minimize(BuildContext context) {
    PIPView.of(context)?.present();
  }

  static void close() {
    _isFloatingShown.value = false;
  }

  static void listen(VoidCallback callback) {
    _isFloatingShown.addListener(callback);
  }
}

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

Let me try it and get back to you. Thank you very much.

from pip_view.

abusaadp avatar abusaadp commented on July 17, 2024

Thank you very much. It is working like a charm.

JazakAllah Khair.

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

Great. You are welcome.
Wa jazak Allahu Khair

from pip_view.

lslv1243 avatar lslv1243 commented on July 17, 2024

Hello, @HasanAlyazidi.
I know it has been a while since you requested the feature, but the new release may achieve what you are looking for. You can use the new more declarative api called RawPIPView, which allows doing all kinds of cool stuff.

from pip_view.

lslv1243 avatar lslv1243 commented on July 17, 2024

Sorry about that, but I just tested it and it is not working as I expected πŸ˜…. When I have free time again, I will fix it and publish a new update.

from pip_view.

lizhuoyuan avatar lizhuoyuan commented on July 17, 2024

it would be great if you could share some examples of how to use the new RawPIPView

from pip_view.

lizhuoyuan avatar lizhuoyuan commented on July 17, 2024

@HasanAlyazidi thanks, your code helped me

from pip_view.

HasanAlyazidi avatar HasanAlyazidi commented on July 17, 2024

@lizhuoyuan You are welcome.

from pip_view.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.