Skip to content
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

Merged
merged 21 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/di.dart
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>[];
}
2 changes: 1 addition & 1 deletion lib/ui/pages/main/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:chat_flutter/config/app_text_size.dart';
import 'package:provider/provider.dart';

class HomePage extends StatelessWidget {
HomePage({Key key}) : super(key:key);
HomePage({Key key}) : super(key: key);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別の箇所で言及しましたが、ここがなくても良いって箇所が他にもありそうですね 🙇

@override
Widget build(BuildContext context) {
return SingleChildScrollView(
Expand Down
10 changes: 6 additions & 4 deletions lib/ui/pages/main/home/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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",
);

の方が自然ですかね?

await Future.delayed(Duration(seconds: 1));
notifyListeners();
}
Expand Down Expand Up @@ -67,4 +69,4 @@ class HomeController with ChangeNotifier{
await Future.delayed(Duration(seconds: 10));
notifyListeners();
}
}
}
69 changes: 34 additions & 35 deletions lib/ui/pages/main/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
Expand Down Expand Up @@ -66,40 +66,39 @@ class MainPage extends StatelessWidget {
Widget bottomNavigation(BuildContext context) {

Choose a reason for hiding this comment

The 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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別箇所でも言及しましたが、const付けれそうですね 👌
https://github.com/flutter/flutter/blob/master/analysis_options.yaml
ここら辺の導入に関してもうまく決めれると良さそうですね 🙆‍♂️

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);
});
}
}
8 changes: 4 additions & 4 deletions lib/ui/pages/main/main_controller.dart
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();
}
}
}
2 changes: 1 addition & 1 deletion lib/ui/pages/main/profile/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _ProfilePage extends StatelessWidget {
Navigator.pushNamed<void>(
context,
"/profileEditPage",
arguments: "test",
arguments: user.name,
);
},
color: Colors.green,
Expand Down
10 changes: 6 additions & 4 deletions lib/ui/pages/main/profile/profile_controller.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:chat_flutter/model/user.dart';

class ProfileController with ChangeNotifier{
ProfileController(){
class ProfileController with ChangeNotifier {
ProfileController() {
getUserById("testId");
print(user.name);
}
User user;

Expand All @@ -13,7 +14,8 @@ class ProfileController with ChangeNotifier{
notifyListeners();
}

void changeProfileInfo() async{
void changeProfileInfo(String s) async {
//Firebaseへの変更通知
print(s);
}
}
}
11 changes: 6 additions & 5 deletions lib/ui/pages/main/profile/profile_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:chat_flutter/config/app_text_size.dart';
class ProfileEditPage extends StatelessWidget {
const ProfileEditPage._({Key key}) : super(key: key);

static Widget wrapped(){
static Widget wrapped() {
return ChangeNotifierProvider<ProfileController>(
create: (_) => ProfileController(),
child: ProfileEditPage._(),
Expand All @@ -22,7 +22,7 @@ class ProfileEditPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
final _user = Provider.of<ProfileController>(context, listen: false).user;
final _user = Provider.of<ProfileController>(context).user;
return Scaffold(
appBar: ProfilePageAppBar(),
backgroundColor: Colors.white,
Expand All @@ -43,7 +43,8 @@ class _ProfileEditPage extends StatelessWidget {
const _ProfileEditPage({Key key, this.user}) : super(key: key);
@override
Widget build(BuildContext context) {
final _profileController = Provider.of<ProfileController>(context, listen: false);
final _profileController =
Provider.of<ProfileController>(context, listen: false);
final TextEditingController _nameController = TextEditingController(
text: ModalRoute.of(context).settings.arguments,
);
Expand Down Expand Up @@ -87,8 +88,8 @@ class _ProfileEditPage extends StatelessWidget {
color: Colors.white,
),
label: Text("更新する"),
onPressed: () {
_profileController.changeProfileInfo();
onPressed: () async {
_profileController.changeProfileInfo(_nameController.text);
Navigator.of(context).pop();
},
color: Colors.redAccent,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/main/talk/talk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class TalkPage extends StatelessWidget {
TalkPage({Key key}) : super(key:key);
TalkPage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final _roomList = Provider.of<TalkController>(context).roomList;
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/pages/main/talk/talk_controller.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:chat_flutter/model/room.dart';

class TalkController with ChangeNotifier{
TalkController(){
class TalkController with ChangeNotifier {
TalkController() {
getRoomList();
}
List<Room> roomList;
Expand Down Expand Up @@ -30,4 +30,4 @@ class TalkController with ChangeNotifier{
await Future.delayed(Duration(seconds: 1));
notifyListeners();
}
}
}