Commit 1900f62d authored by Nguyen Hoang Giang's avatar Nguyen Hoang Giang

Fix Bug and RiveNav

parent 9c53052f
import 'package:instagram_clone/models/rive_assets.dart';
class Menu{
String title;
RiveModel rive;
Menu({
required this.rive,
required this.title,
});
}
List<Menu> menu_list = [
Menu(
rive: RiveModel(
src: "assets/RiveAssets/icons.riv",
artboard: "HOME",
stateMachineName: "HOME_interactivity"
),
title: "Home"
),
Menu(
rive: RiveModel(
src: "assets/RiveAssets/icons.riv",
artboard: "SEARCH",
stateMachineName: "SEARCH_Interactivity"
),
title: "SEARCH"
),
Menu(
title: "Timer",
rive: RiveModel(
src: "assets/RiveAssets/icons.riv",
artboard: "TIMER",
stateMachineName: "TIMER_Interactivity"),
),
Menu(
title: "Notification",
rive: RiveModel(
src: "assets/RiveAssets/icons.riv",
artboard: "BELL",
stateMachineName: "BELL_Interactivity"),
),
];
\ No newline at end of file
import 'package:rive/rive.dart';
class RiveModel{
String src, artboard, stateMachineName;
SMIBool? status;
RiveModel({
required this.src,
required this.artboard,
required this.stateMachineName,
this.status});
void setStatus(SMIBool newStatus){
this.status = status;
}
}
\ No newline at end of file
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart'; import 'package:instagram_clone/models/menu.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:instagram_clone/screens/post_screen.dart'; import 'package:instagram_clone/screens/post_screen.dart';
import 'package:instagram_clone/screens/profile_screen.dart'; import 'package:instagram_clone/screens/profile_screen.dart';
import 'package:instagram_clone/screens/search_screen.dart'; import 'package:instagram_clone/screens/search_screen.dart';
import 'package:instagram_clone/screens/video_screen.dart'; import 'package:instagram_clone/screens/video_screen.dart';
import 'package:instagram_clone/utils/rive_utils.dart';
import 'package:instagram_clone/utils/text_utils.dart'; import 'package:instagram_clone/utils/text_utils.dart';
import 'package:instagram_clone/widgets/btn_bottom_navigator.dart';
import 'home_screen.dart'; import 'home_screen.dart';
...@@ -18,6 +20,7 @@ class MainScreen extends StatefulWidget { ...@@ -18,6 +20,7 @@ class MainScreen extends StatefulWidget {
} }
class _MainScreenState extends State<MainScreen> { class _MainScreenState extends State<MainScreen> {
Menu selectedNavItem = menu_list.first;
int index = 0; int index = 0;
final TextUtils _textUtils = TextUtils(); final TextUtils _textUtils = TextUtils();
final PageController pageController = PageController( final PageController pageController = PageController(
...@@ -29,9 +32,76 @@ class _MainScreenState extends State<MainScreen> { ...@@ -29,9 +32,76 @@ class _MainScreenState extends State<MainScreen> {
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
body: getScreen(), body: getScreen(),
bottomNavigationBar: bottomBarWidget(), bottomNavigationBar: bottomBarRiveWidget(),
); );
} }
Widget bottomBarRiveWidget(){
return SafeArea(
child: Container(
padding: const EdgeInsets.all(12),
margin: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.8),
borderRadius: const BorderRadius.all(Radius.circular(24)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
offset: const Offset(0, 20),
blurRadius: 20,
),
]
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
...List.generate(menu_list.length, (index) =>
BtnNavButton(
menu: menu_list[index],
onTap: () {
RiveUtils.changeSMIBoolState(menu_list[index].rive.status!);
updateNavBtn(index, menu_list[index]);
},
riveOnInit: (artboard) {
menu_list[index].rive.status = RiveUtils.getRiveInput(
artboard,
stateMachineName: menu_list[index].rive.stateMachineName,
);
},
activeMenu: selectedNavItem,
),
),
InkWell(
onTap: () {
index = 4;
setState(() {
});
},
child: CircleAvatar(
backgroundColor: index == 4 ? Colors.black : Colors.white,
radius: 17,
child: const CircleAvatar(
radius: 15,
backgroundImage: AssetImage("assets/avaters/Avatar 1.jpg"),
),
),
),
],
),
),
);
}
void updateNavBtn(int newIndex, Menu newNavBtn){
setState(() {
index = newIndex;
selectedNavItem = newNavBtn;
});
}
Widget bottomBarWidget() { Widget bottomBarWidget() {
return Container( return Container(
......
...@@ -40,17 +40,17 @@ class _StoryScreenState extends State<StoryScreen> with TickerProviderStateMixin ...@@ -40,17 +40,17 @@ class _StoryScreenState extends State<StoryScreen> with TickerProviderStateMixin
@override @override
void dispose() { void dispose() {
// TODO: implement dispose // TODO: implement dispose
_pageController.dispose();
_cancelTimer(); _cancelTimer();
// Future.delayed(const Duration(milliseconds: 500)).then((value) {_pageController.dispose();});
super.dispose(); super.dispose();
} }
@override
void _cancelTimer() { void _cancelTimer() async{
_timer?.cancel(); _timer?.cancel();
} }
...@@ -80,11 +80,11 @@ class _StoryScreenState extends State<StoryScreen> with TickerProviderStateMixin ...@@ -80,11 +80,11 @@ class _StoryScreenState extends State<StoryScreen> with TickerProviderStateMixin
} else { } else {
if (_current_page < list_image.length - 1){ if (_current_page < list_image.length - 1){
_current_page++; _current_page++;
print("Still Run");
_pageController.animateToPage( _pageController.animateToPage(
_current_page, _current_page,
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
curve: Curves.easeOut); curve: Curves.easeOut,
);
_current_timer = 0.0; _current_timer = 0.0;
_duration = 10000; _duration = 10000;
...@@ -272,7 +272,7 @@ class _StoryScreenState extends State<StoryScreen> with TickerProviderStateMixin ...@@ -272,7 +272,7 @@ class _StoryScreenState extends State<StoryScreen> with TickerProviderStateMixin
void returnHome() { void returnHome() {
_current_page = 0; _current_page = 0;
_pageController = PageController(initialPage: _current_page); // _pageController = PageController(initialPage: _current_page);
_duration = 10000; _duration = 10000;
_current_timer = 0.0; _current_timer = 0.0;
_previous_page = _current_page; _previous_page = _current_page;
......
import 'package:rive/rive.dart';
class RiveUtils{
static SMIBool getRiveInput(Artboard artboard, {required String stateMachineName}){
StateMachineController? controller = StateMachineController.fromArtboard(artboard, stateMachineName);
artboard.addController(controller!);
return controller.findInput<bool>("active") as SMIBool;
}
static void changeSMIBoolState(SMIBool input) {
input.change(true);
Future.delayed(
const Duration(seconds: 1),
() {
input.change(false);
}
);
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:instagram_clone/models/menu.dart';
import 'package:rive/rive.dart';
class BtnNavButton extends StatelessWidget {
final Menu menu;
final VoidCallback onTap;
final ValueChanged<Artboard> riveOnInit;
final Menu activeMenu;
const BtnNavButton({super.key, required this.menu, required this.onTap, required this.riveOnInit, required this.activeMenu});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
AnimatedContainer(
margin: const EdgeInsets.only(bottom: 2),
duration: const Duration(milliseconds: 400),
height: 4,
width: activeMenu == menu ? 20: 0,
decoration: const BoxDecoration(
color: Color(0xFF81B4FF),
borderRadius: BorderRadius.all(Radius.circular(12)),
),
),
SizedBox(
width: 36,
height: 36,
child: Opacity(
opacity: activeMenu == menu ? 1 : 0.5,
child: RiveAnimation.asset(
menu.rive.src,
artboard: menu.rive.artboard,
onInit: riveOnInit,
),
),
),
],
),
);
}
}
\ No newline at end of file
...@@ -26,6 +26,8 @@ class CubeWidget extends StatefulWidget { ...@@ -26,6 +26,8 @@ class CubeWidget extends StatefulWidget {
} }
class _CubeWidgetState extends State<CubeWidget> { class _CubeWidgetState extends State<CubeWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isLeaving = (widget.index - widget.pageNotifier) <= 0; final isLeaving = (widget.index - widget.pageNotifier) <= 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment