-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ChangeNotifierの実装(メインページ) #16
Changes from 1 commit
b4aaa0c
387cca8
f72e08d
9044e30
ebdf747
3cafa59
0cf5f17
abcd197
9179ad5
02f1e31
e41481e
1ef3712
4959e8f
52cdb0c
53080e9
61ce4a2
7c87aa9
1e9cb92
6b8e569
ab57921
0002225
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import 'package:provider/single_child_widget.dart'; | ||
|
||
List<SingleChildWidget> get providers { | ||
return <SingleChildWidget>[ | ||
]; | ||
return <SingleChildWidget>[]; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,8 +2,8 @@ import 'package:chat_flutter/model/group.dart'; | |||||||||||||||
import 'package:chat_flutter/model/user.dart'; | ||||||||||||||||
import 'package:flutter/material.dart'; | ||||||||||||||||
|
||||||||||||||||
class HomeController with ChangeNotifier{ | ||||||||||||||||
HomeController(){ | ||||||||||||||||
class HomeController with ChangeNotifier { | ||||||||||||||||
HomeController() { | ||||||||||||||||
getMeById("userId"); | ||||||||||||||||
getGroupList(); | ||||||||||||||||
getFriendList(); | ||||||||||||||||
|
@@ -13,7 +13,9 @@ class HomeController with ChangeNotifier{ | |||||||||||||||
List<User> friendList; | ||||||||||||||||
|
||||||||||||||||
void getMeById(String userId) async { | ||||||||||||||||
user = User(name: "test", imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg"); | ||||||||||||||||
user = User( | ||||||||||||||||
name: "test", | ||||||||||||||||
imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg"); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
の方が自然ですかね? |
||||||||||||||||
await Future.delayed(Duration(seconds: 1)); | ||||||||||||||||
notifyListeners(); | ||||||||||||||||
} | ||||||||||||||||
|
@@ -67,4 +69,4 @@ class HomeController with ChangeNotifier{ | |||||||||||||||
await Future.delayed(Duration(seconds: 10)); | ||||||||||||||||
notifyListeners(); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,11 @@ import 'package:flutter/material.dart'; | |
import 'package:provider/provider.dart'; | ||
|
||
class MainPage extends StatelessWidget { | ||
MainPage._({Key key}) : super(key:key); | ||
MainPage._({Key key}) : super(key: key); | ||
|
||
static Widget wrapped(){ | ||
static Widget wrapped() { | ||
return MultiProvider( | ||
providers:[ | ||
providers: [ | ||
ChangeNotifierProvider<MainController>( | ||
create: (_) => MainController(), | ||
), | ||
|
@@ -66,40 +66,39 @@ class MainPage extends StatelessWidget { | |
Widget bottomNavigation(BuildContext context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 逆にここは他のファイルから参照されていなければprivateにして良さそうです 👌 |
||
final _controller = Provider.of<MainController>(context); | ||
return BottomNavigationBar( | ||
backgroundColor: Colors.white, | ||
type: BottomNavigationBarType.fixed, | ||
showSelectedLabels: false, | ||
showUnselectedLabels: false, | ||
currentIndex: _controller.currentIndex, | ||
items: [ | ||
BottomNavigationBarItem( | ||
icon: Icon( | ||
Icons.home, | ||
backgroundColor: Colors.white, | ||
type: BottomNavigationBarType.fixed, | ||
showSelectedLabels: false, | ||
showUnselectedLabels: false, | ||
currentIndex: _controller.currentIndex, | ||
items: [ | ||
BottomNavigationBarItem( | ||
icon: Icon( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 別箇所でも言及しましたが、 |
||
Icons.home, | ||
), | ||
title: Text( | ||
"", | ||
), | ||
), | ||
title: Text( | ||
"", | ||
BottomNavigationBarItem( | ||
icon: Icon( | ||
Icons.message, | ||
), | ||
title: Text( | ||
"", | ||
), | ||
), | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon( | ||
Icons.message, | ||
), | ||
title: Text( | ||
"", | ||
), | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon( | ||
Icons.person, | ||
BottomNavigationBarItem( | ||
icon: Icon( | ||
Icons.person, | ||
), | ||
title: Text( | ||
"", | ||
), | ||
), | ||
title: Text( | ||
"", | ||
), | ||
), | ||
], | ||
onTap: (index){ | ||
_controller.changePage(index); | ||
} | ||
); | ||
], | ||
onTap: (index) { | ||
_controller.changePage(index); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class MainController with ChangeNotifier{ | ||
class MainController with ChangeNotifier { | ||
int currentIndex; | ||
MainController(){ | ||
MainController() { | ||
currentIndex = 0; | ||
} | ||
|
||
void changePage(int index){ | ||
void changePage(int index) { | ||
currentIndex = index; | ||
notifyListeners(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
別の箇所で言及しましたが、ここがなくても良いって箇所が他にもありそうですね 🙇