분류, 패키지 및 저장소 검색

GitHub 저장소Bestfastfire/fragment_navigate

fragment_navigate

네이티브 안드로이드에서처럼 프래그먼트를 전환하는 효과를 구현하기 위한 컨트롤러입니다.

fragment_navigate 프로젝트 이미지
스타
14
포크
3
최근 푸시(UTC)
2022. 7. 7.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

Fragment Navigate

Check it out at Pub.Dev

A controller to make the effect of swapping fragments like in native Android.

ezgif com-video-to-gif-2

Stack Feature:

ezgif com-video-to-gif

Help Maintenance

I've been maintaining quite many repos these days and burning out slowly. If you could help me cheer up, buying me a cup of coffee will make my life really happy and get much energy out of it.

Buy Me A Coffee

Getting Started

You must first create an object with the following attributes:

static final _fragNav = FragNavigate(
    firstKey: 'a',
    screens: <Posit>[
        // T is typeof "params"
        Posit<T>(
          key: a,
          title: 'Title A',
          fragmentBuilder: (p) => Container(color: Colors.amberAccent),
          params: {'value': "x"}
        ),
        Posit(
          key: b,
          title: 'Title B',
          fragmentBuilder: (p) => Text('Test B...')
        ),
        Posit(
          key: c,
          title: 'Title C',
          fragmentBuilder: (p) => Container(color: Colors.blueAccent,)
        ),
        Posit(
          key: d,
          title: 'Title D',
          fragmentBuilder: (p) => Text(p as String)
        ),
    ],
    actionsList: [
        ActionPosit(
          keys: [a, b, c],
          actions: [
            IconButton(
              icon: Icon(Icons.add),
              onPressed: (){
                _fragNav.action('teste');
              }
            )
          ]
        )
      ],
  bottomList: [
    BottomPosit(
      keys: [a, b, c],
      length: 2,
      child: TabBar(
        indicatorColor: Colors.white,
        tabs: <Widget>[
          Text('a'),
          Text('b')
        ],
      )
    )
  ]
)
Screens:

In Screens, you need pass one list of Posit, to every Posit in screens, you need pass one unique key, one title and one Widget

ActionsList:

Here you pass one list of ActionPosit, to every ActionPosit, you parse one list of keys and one list of Widgets, the keys is the same keys of screens to show this actions. In click action of your Widget, you can call _fragNav.action('tag', params: 'any object');

_fragNav.action('tag')

To use it, your widget need implements interface: ActionInterface, and the action will called in:

@override
void action(String tag, {dynamic params}) {
    switch(tag){
        case 'tag': ...
    }
}
BottomList:

Here is like ActionsList, but the difference is you need pass length of tabs and the child is one PreferedSizedWidget.

Mounting Layout

Case the controller of fragments is one Drawer, you need set in build this value: _fragNav.setDrawerContext = context;, this is useful when you change fragment or click in back button, Case the controller of fragments is one Drawer, you need set in build this value: _fragNav.setDrawerContext = context;, this is useful when you change fragment or click in back button, then drawer close.

@override
Widget build(BuildContext context) {
    _fragNav.setDrawerContext = context;

    return StreamBuilder<FullPosit>(
        stream: _fragNav.outStreamFragment,
        builder: (con, s){
          if(s.data != null){
            if(s.data!.params is Map){
              print('Params passeds: ${s.data?.params}');
              
            }
        
            return DefaultTabController(
                length: s.data.bottom.length,
                child: Scaffold(
                  key: _fragNav.drawerKey,
                  appBar: AppBar(
                    title: Text(s.data.title),
                    actions: s.data.actions,
                    bottom: s.data.bottom.child,
                  ),
                  drawer: CustomDrawer(bloc: _fragNav),
                  body: ScreenNavigate(
                      child: s.data.fragment,
                      control: _fragNav
                  ),
                )
            );
        }

      return Container();
    }
);

Use one StreamBuilder passing like stream _fragNav.outStreamFragment, and it return one FullPosit:

FullPosit(
  bottom: => BottomPosit(
      keys => list,
      length => size, 
      child => PreferedSizedWidget
  ),
  key: key,
  actions: actions,
  title: title,
  fragment: fragment,
);

IMPORTANT Case you will use the BottomList, remember that you need pass your Scaffold in one TabController like example above.

To set actual fragment, title and bottom only make this in scaffold:

Scaffold(
  key: _fragNav.drawerKey, // Pass it to controller Drawer on back and on put fragment
  appBar: AppBar(
    title: Text(snapshot.data.title),
    actions: snapshot.data.actions,
    bottom: snapshot.data.bottom.child,
  ),
  drawer: CustomDrawer(bloc: _fragNav),
  body: ScreenNavigate(
      child: snapshot.data.fragment,
      control: _fragNav
  ),
)

ScreenNavigate

In body of Scaffold, pass the ScreenNavigate like this:

ScreenNavigate(
  child: snapshot.data.fragment,
  control: _fragNav
)

It will make effect FadeIn on changed fragments.

Drawer

In every item of Drawer that call one new fragment ou can do it:

ListTile(
  leading: Icon(Icons.settings, color: currentSelect == key ? Colors.white : null), //
  selected: currentSelect == key, //here and above show how you can change color of selected fragment item
  title: Text(text, style: TextStyle(color: _getColor())),
  onTap: () => _fragNav.putPosit(key: newKey),
)
Change Fragment

To change fragment you can call in FragNavigate methods:

putPosit<K>(key, force => default false, closeDrawer => default true, K? params => Params to pass for fragmentBuilder); //put new fragment in stack
putAndReplace<K>(key, force => default false, closeDrawer => default true, K? params => Params to pass for fragmentBuilder); //put and discart atual fragment in stack
putAndClean<K>(key, force => default false, closeDrawer => default true, K? params => Params to pass for fragmentBuilder); //put and clean stack
jumpBack(); //back to last in stack, it is called automatically if you click in back buttom
jumpBackToFirst(); //back to first in stack and clean it
Woton Sampaio GitHub avatar
GitHub 작성자

Woton Sampaio ↗

Mobile native/Flutter Developer

Clean Code
언어DartSwiftKotlinObjective-C

분류

사용 중인 의존성

의존성 목록 3 개

  • flutter{"sdk":"flutter"}
  • rxdart^0.27.4
  • flutter_test개발 의존성{"sdk":"flutter"}

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗