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 19 commits
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
11 changes: 0 additions & 11 deletions lib/di.dart

This file was deleted.

17 changes: 5 additions & 12 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:chat_flutter/di.dart';
import 'package:chat_flutter/ui/pages/add_friend.dart';
import 'package:chat_flutter/ui/pages/create_group.dart';
import 'package:chat_flutter/ui/pages/main.dart';
import 'package:chat_flutter/ui/pages/profile_edit.dart';
import 'package:chat_flutter/ui/pages/profile.dart';
import 'package:chat_flutter/ui/pages/main/main.dart';
import 'package:chat_flutter/ui/pages/main/profile/profile_edit.dart';
import 'package:chat_flutter/ui/pages/room.dart';
import 'package:chat_flutter/ui/pages/sign_in.dart';
import 'package:chat_flutter/ui/pages/sign_up.dart';

void main() {
runApp(
MultiProvider(
providers: providers,
child: MyApp(),
),
MyApp(),
);
}

Expand All @@ -32,12 +26,11 @@ class MyApp extends StatelessWidget {
),
initialRoute: '/mainPage',
routes: {
'/mainPage': (context) => MainPage(),
'/mainPage': (context) => MainPage.wrapped(),
'/signUpPage': (context) => SignUpPage(),
'/signInPage': (context) => SignInPage(),
'/roomPage': (context) => RoomPage(),
'/profilePage': (context) => ProfilePage(),
'/profileEditPage': (context) => ProfileEditPage(),
'/profileEditPage': (context) => ProfileEditPage.wrapped(),
'/addFriendPage': (context) => AddFriendPage(),
'/createGroupPage': (context) => CreateGroupPage(),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/user.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:chat_flutter/services/user.dart';
import 'package:flutter/material.dart';

import '../model/user.dart';
import 'package:chat_flutter/model/user.dart';

class UserProvider with ChangeNotifier {
UserProvider() {
Expand Down
50 changes: 50 additions & 0 deletions lib/ui/molecules/home/friend_tile_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:chat_flutter/config/app_space.dart';

import 'package:chat_flutter/ui/molecules/home/list_tile.dart';

import 'package:chat_flutter/ui/pages/main/home/home_controller.dart';

class FriendTileList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final friendList = Provider.of<HomeController>(context).friendList;
if (friendList == null) {
return const Center(
child: CircularProgressIndicator(),
);
} else {
return Container(
// ここのラップは適当にサイズ指定しているだけなので、レイアウトに合わせて変更する必要あり
height: 220,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: AppSpace.small,
),
ListView.builder(
physics: ScrollPhysics(),
scrollDirection: Axis.vertical,

Choose a reason for hiding this comment

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

https://api.flutter.dev/flutter/widgets/ListView/ListView.builder.html
今更で申し訳ないんですけどここは defaultがAxis.verticalなのでいらなさそうですね 🆗

Suggested change
scrollDirection: Axis.vertical,

shrinkWrap: true,
itemCount: friendList.length,
itemBuilder: (
BuildContext context,
int index,
) {
return HomePageListTile(
name: friendList[index].name,
imgUrl: friendList[index].imgUrl,
);
},
),
],
),
),
);
}
}
}
48 changes: 48 additions & 0 deletions lib/ui/molecules/home/group_tile_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:chat_flutter/config/app_space.dart';

import 'package:chat_flutter/ui/molecules/home/list_tile.dart';

import 'package:chat_flutter/ui/pages/main/home/home_controller.dart';

class GroupTileList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final groupList = Provider.of<HomeController>(context).groupList;
if (groupList == null) {
return const Center(
child: CircularProgressIndicator(),
);
}
return Container(
height: 220,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: AppSpace.small,
),
ListView.builder(
physics: ScrollPhysics(),
scrollDirection: Axis.vertical,

Choose a reason for hiding this comment

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

shrinkWrap: true,
itemCount: groupList.length,
itemBuilder: (
BuildContext context,
int index,
) {
return HomePageListTile(
name: groupList[index].name,
imgUrl: groupList[index].imgUrl,
);
},
),
],
),
),
);
}
}
23 changes: 23 additions & 0 deletions lib/ui/molecules/home/my_tile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:chat_flutter/ui/molecules/home/list_tile.dart';

import 'package:chat_flutter/ui/pages/main/home/home_controller.dart';

class MyTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
final user = Provider.of<HomeController>(context).user;
if (user == null) {
return const Center(
child: CircularProgressIndicator(),
);
}
return HomePageListTile(
name: user.name,
imgUrl: user.imgUrl,
isMe: true,
);
}
}
Loading