-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve categories type state management (#99)
* refactor: improve categories type state management * refactor: improve categories type state management Co-authored-by: André Masson <[email protected]>
- Loading branch information
1 parent
822c999
commit 8f39783
Showing
11 changed files
with
77 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 7 additions & 29 deletions
36
lib/theme/widgets/responsive/navigation/responsive.navigation.rail.or.bar.widget.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,23 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'navigation.choices.model.dart'; | ||
import 'navigation.landscape.layout.dart'; | ||
import 'navigation.portrait.layout.widget.dart'; | ||
|
||
class ResponsiveNavigationRailOrBar extends StatefulWidget { | ||
class ResponsiveNavigationRailOrBar extends StatelessWidget { | ||
final List<NavigationChoices> items; | ||
final int currentIndex; | ||
final Widget Function(int index) childBuilder; | ||
|
||
const ResponsiveNavigationRailOrBar( | ||
{Key? key, required this.items, required this.childBuilder, this.currentIndex = 0}) | ||
: super(key: key); | ||
|
||
@override | ||
State<ResponsiveNavigationRailOrBar> createState() => _ResponsiveNavigationRailOrBarState(); | ||
} | ||
|
||
class _ResponsiveNavigationRailOrBarState extends State<ResponsiveNavigationRailOrBar> { | ||
late int currentIndex; | ||
late Widget child; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
currentIndex = widget.currentIndex; | ||
child = widget.childBuilder(widget.currentIndex); | ||
} | ||
final Widget child; | ||
final Function(int index) onTap; | ||
|
||
void onTap(int index) { | ||
setState(() { | ||
currentIndex = index; | ||
child = widget.childBuilder(index); | ||
}); | ||
} | ||
const ResponsiveNavigationRailOrBar({Key? key, required this.items, required this.currentIndex, required this.child, required this.onTap}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) => OrientationBuilder( | ||
builder: (context, orientation) { | ||
return orientation == Orientation.portrait | ||
? NavigationPortraitLayout(items: widget.items, currentIndex: currentIndex, onTap: onTap, child: child) | ||
: NavigationLandscapeLayout(items: widget.items, currentIndex: currentIndex, onTap: onTap, child: child); | ||
? NavigationPortraitLayout(items: items, currentIndex: currentIndex, onTap: onTap, child: child) | ||
: NavigationLandscapeLayout(items: items, currentIndex: currentIndex, onTap: onTap, child: child); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters