From b4aaa0ce58c5ef5be8603e53bc75d8b114a9a24a Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 14:57:18 +0900 Subject: [PATCH 01/20] =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=94?= =?UTF-8?q?=E3=81=A8=E3=81=AB=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88?= =?UTF-8?q?=E3=83=AA=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 6 +++--- lib/ui/pages/{ => main/home}/home.dart | 0 lib/ui/pages/{ => main}/main.dart | 6 +++--- lib/ui/pages/{ => main/profile}/profile.dart | 0 lib/ui/pages/{ => main/profile}/profile_edit.dart | 0 lib/ui/pages/{ => main/talk}/talk.dart | 0 6 files changed, 6 insertions(+), 6 deletions(-) rename lib/ui/pages/{ => main/home}/home.dart (100%) rename lib/ui/pages/{ => main}/main.dart (91%) rename lib/ui/pages/{ => main/profile}/profile.dart (100%) rename lib/ui/pages/{ => main/profile}/profile_edit.dart (100%) rename lib/ui/pages/{ => main/talk}/talk.dart (100%) diff --git a/lib/main.dart b/lib/main.dart index e71ba03..224777d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,9 +4,9 @@ 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/main/profile/profile.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'; diff --git a/lib/ui/pages/home.dart b/lib/ui/pages/main/home/home.dart similarity index 100% rename from lib/ui/pages/home.dart rename to lib/ui/pages/main/home/home.dart diff --git a/lib/ui/pages/main.dart b/lib/ui/pages/main/main.dart similarity index 91% rename from lib/ui/pages/main.dart rename to lib/ui/pages/main/main.dart index 006539f..ee9f0ae 100644 --- a/lib/ui/pages/main.dart +++ b/lib/ui/pages/main/main.dart @@ -1,9 +1,9 @@ import 'package:chat_flutter/ui/molecules/home/app_bar.dart'; import 'package:chat_flutter/ui/molecules/profile/app_bar.dart'; import 'package:chat_flutter/ui/molecules/talk/app_bar.dart'; -import 'package:chat_flutter/ui/pages/home.dart'; -import 'package:chat_flutter/ui/pages/profile.dart'; -import 'package:chat_flutter/ui/pages/talk.dart'; +import 'package:chat_flutter/ui/pages/main/home/home.dart'; +import 'package:chat_flutter/ui/pages/main/profile/profile.dart'; +import 'package:chat_flutter/ui/pages/main/talk/talk.dart'; import 'package:flutter/material.dart'; class MainPage extends StatefulWidget { diff --git a/lib/ui/pages/profile.dart b/lib/ui/pages/main/profile/profile.dart similarity index 100% rename from lib/ui/pages/profile.dart rename to lib/ui/pages/main/profile/profile.dart diff --git a/lib/ui/pages/profile_edit.dart b/lib/ui/pages/main/profile/profile_edit.dart similarity index 100% rename from lib/ui/pages/profile_edit.dart rename to lib/ui/pages/main/profile/profile_edit.dart diff --git a/lib/ui/pages/talk.dart b/lib/ui/pages/main/talk/talk.dart similarity index 100% rename from lib/ui/pages/talk.dart rename to lib/ui/pages/main/talk/talk.dart From 387cca8f017d78b64a9212f148a4638d77636e33 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 15:01:35 +0900 Subject: [PATCH 02/20] =?UTF-8?q?ChangeNotifier=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E3=82=92=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/pages/main/home/home_controller.dart | 5 +++++ lib/ui/pages/main/main_controller.dart | 5 +++++ lib/ui/pages/main/profile/profile_controller.dart | 5 +++++ lib/ui/pages/main/profile/profile_edit_controller.dart | 5 +++++ lib/ui/pages/main/talk/talk_controller.dart | 5 +++++ 5 files changed, 25 insertions(+) create mode 100644 lib/ui/pages/main/home/home_controller.dart create mode 100644 lib/ui/pages/main/main_controller.dart create mode 100644 lib/ui/pages/main/profile/profile_controller.dart create mode 100644 lib/ui/pages/main/profile/profile_edit_controller.dart create mode 100644 lib/ui/pages/main/talk/talk_controller.dart diff --git a/lib/ui/pages/main/home/home_controller.dart b/lib/ui/pages/main/home/home_controller.dart new file mode 100644 index 0000000..83c8456 --- /dev/null +++ b/lib/ui/pages/main/home/home_controller.dart @@ -0,0 +1,5 @@ +import 'package:flutter/material.dart'; + +class HomeController with ChangeNotifier{ + +} \ No newline at end of file diff --git a/lib/ui/pages/main/main_controller.dart b/lib/ui/pages/main/main_controller.dart new file mode 100644 index 0000000..ba50b5a --- /dev/null +++ b/lib/ui/pages/main/main_controller.dart @@ -0,0 +1,5 @@ +import 'package:flutter/material.dart'; + +class MainController with ChangeNotifier{ + +} \ No newline at end of file diff --git a/lib/ui/pages/main/profile/profile_controller.dart b/lib/ui/pages/main/profile/profile_controller.dart new file mode 100644 index 0000000..0eecea0 --- /dev/null +++ b/lib/ui/pages/main/profile/profile_controller.dart @@ -0,0 +1,5 @@ +import 'package:flutter/material.dart'; + +class ProfileController with ChangeNotifier{ + +} \ No newline at end of file diff --git a/lib/ui/pages/main/profile/profile_edit_controller.dart b/lib/ui/pages/main/profile/profile_edit_controller.dart new file mode 100644 index 0000000..62bb24e --- /dev/null +++ b/lib/ui/pages/main/profile/profile_edit_controller.dart @@ -0,0 +1,5 @@ +import 'package:flutter/material.dart'; + +class ProfileEditController with ChangeNotifier{ + +} \ No newline at end of file diff --git a/lib/ui/pages/main/talk/talk_controller.dart b/lib/ui/pages/main/talk/talk_controller.dart new file mode 100644 index 0000000..05f9f34 --- /dev/null +++ b/lib/ui/pages/main/talk/talk_controller.dart @@ -0,0 +1,5 @@ +import 'package:flutter/material.dart'; + +class TalkController with ChangeNotifier{ + +} \ No newline at end of file From f72e08d27f66bacb8682f2852bad9468a4eaccf8 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 15:53:30 +0900 Subject: [PATCH 03/20] mainController --- lib/ui/pages/main/main.dart | 36 ++++++++++---------------- lib/ui/pages/main/main_controller.dart | 10 ++++++- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/ui/pages/main/main.dart b/lib/ui/pages/main/main.dart index ee9f0ae..f9b60fe 100644 --- a/lib/ui/pages/main/main.dart +++ b/lib/ui/pages/main/main.dart @@ -2,25 +2,16 @@ import 'package:chat_flutter/ui/molecules/home/app_bar.dart'; import 'package:chat_flutter/ui/molecules/profile/app_bar.dart'; import 'package:chat_flutter/ui/molecules/talk/app_bar.dart'; import 'package:chat_flutter/ui/pages/main/home/home.dart'; +import 'package:chat_flutter/ui/pages/main/main_controller.dart'; import 'package:chat_flutter/ui/pages/main/profile/profile.dart'; import 'package:chat_flutter/ui/pages/main/talk/talk.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; -class MainPage extends StatefulWidget { - @override - _MainPageState createState() => _MainPageState(); -} - -class _MainPageState extends State { - int _currentIndex = 0; - void changePage(int index) { - setState( - () => _currentIndex = index, - ); - } - +class MainPage extends StatelessWidget { @override Widget build(BuildContext context) { + final _mainController = Provider.of(context); final List appBarList = [ HomePageAppBar(), TalkPageAppBar(), @@ -40,20 +31,21 @@ class _MainPageState extends State { ]; return Scaffold( - appBar: appBarList[_currentIndex], - backgroundColor: backgroundColor[_currentIndex], - bottomNavigationBar: bottomNavigation(), - body: pages[_currentIndex], + appBar: appBarList[_mainController.currentIndex], + backgroundColor: backgroundColor[_mainController.currentIndex], + bottomNavigationBar: bottomNavigation(context), + body: pages[_mainController.currentIndex], ); } - Widget bottomNavigation() { + Widget bottomNavigation(BuildContext context) { + final _mainController = Provider.of(context); return BottomNavigationBar( backgroundColor: Colors.white, type: BottomNavigationBarType.fixed, showSelectedLabels: false, showUnselectedLabels: false, - currentIndex: _currentIndex, + currentIndex: _mainController.currentIndex, items: [ BottomNavigationBarItem( icon: Icon( @@ -80,9 +72,9 @@ class _MainPageState extends State { ), ), ], - onTap: (index) => setState( - () => _currentIndex = index, - ), + onTap: (index){ + _mainController.changePage(index); + } ); } } diff --git a/lib/ui/pages/main/main_controller.dart b/lib/ui/pages/main/main_controller.dart index ba50b5a..1de3614 100644 --- a/lib/ui/pages/main/main_controller.dart +++ b/lib/ui/pages/main/main_controller.dart @@ -1,5 +1,13 @@ import 'package:flutter/material.dart'; class MainController with ChangeNotifier{ - + int currentIndex; + MainController(){ + currentIndex = 0; + } + + void changePage(int index){ + currentIndex = index; + notifyListeners(); + } } \ No newline at end of file From 9044e305c3fe45f5c1aad6df48da1668fc090a25 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 15:59:45 +0900 Subject: [PATCH 04/20] talkController --- lib/ui/pages/main/talk/talk.dart | 5 +++- lib/ui/pages/main/talk/talk_controller.dart | 27 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/ui/pages/main/talk/talk.dart b/lib/ui/pages/main/talk/talk.dart index 5c37230..9934025 100644 --- a/lib/ui/pages/main/talk/talk.dart +++ b/lib/ui/pages/main/talk/talk.dart @@ -1,6 +1,8 @@ import 'package:chat_flutter/ui/molecules/talk/list_tile.dart'; +import 'package:chat_flutter/ui/pages/main/talk/talk_controller.dart'; import 'package:flutter/material.dart'; import 'package:chat_flutter/model/room.dart'; +import 'package:provider/provider.dart'; class TalkPage extends StatefulWidget { @override @@ -10,8 +12,9 @@ class TalkPage extends StatefulWidget { class _TalkPageState extends State { @override Widget build(BuildContext context) { + final _talkController = Provider.of(context); return FutureBuilder( - future: _getRoomList(), + future: _talkController.getRoomList(), builder: ( BuildContext context, AsyncSnapshot> snapshot, diff --git a/lib/ui/pages/main/talk/talk_controller.dart b/lib/ui/pages/main/talk/talk_controller.dart index 05f9f34..508e3a4 100644 --- a/lib/ui/pages/main/talk/talk_controller.dart +++ b/lib/ui/pages/main/talk/talk_controller.dart @@ -1,5 +1,30 @@ import 'package:flutter/material.dart'; +import 'package:chat_flutter/model/room.dart'; class TalkController with ChangeNotifier{ - + Future> getRoomList() async { + final List roomList = [ + Room( + name: "Sport", + imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", + lastMessage: "hello,group!", + sendTime: "23:04", + ), + Room( + name: "Study", + imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", + lastMessage: "hey!", + sendTime: "21:04", + ), + Room( + name: "Hobby", + imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", + lastMessage: "amusement Park!!!!", + sendTime: "20:04", + ), + ]; + + await Future.delayed(Duration(seconds: 1)); + return await Future.value(roomList); + } } \ No newline at end of file From ebdf7475f160207e9900e29a68661990c194a655 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 16:07:18 +0900 Subject: [PATCH 05/20] profileController --- lib/providers/user.dart | 2 +- lib/ui/pages/main/profile/profile.dart | 6 +++--- lib/ui/pages/main/profile/profile_controller.dart | 10 +++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/providers/user.dart b/lib/providers/user.dart index ed79b32..cc4d2bc 100644 --- a/lib/providers/user.dart +++ b/lib/providers/user.dart @@ -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() { diff --git a/lib/ui/pages/main/profile/profile.dart b/lib/ui/pages/main/profile/profile.dart index 197fa92..06f3445 100644 --- a/lib/ui/pages/main/profile/profile.dart +++ b/lib/ui/pages/main/profile/profile.dart @@ -1,6 +1,6 @@ import 'package:chat_flutter/config/app_space.dart'; -import 'package:chat_flutter/providers/user.dart'; import 'package:chat_flutter/ui/atoms/profile_image.dart'; +import 'package:chat_flutter/ui/pages/main/profile/profile_controller.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -12,9 +12,9 @@ class ProfilePage extends StatelessWidget { const ProfilePage({Key key}) : super(key: key); @override Widget build(BuildContext context) { - final userProvider = Provider.of(context); + final _profileController = Provider.of(context); return FutureBuilder( - future: userProvider.getUserById("userId"), + future: _profileController.getUserById("userId"), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); diff --git a/lib/ui/pages/main/profile/profile_controller.dart b/lib/ui/pages/main/profile/profile_controller.dart index 0eecea0..2cfd1db 100644 --- a/lib/ui/pages/main/profile/profile_controller.dart +++ b/lib/ui/pages/main/profile/profile_controller.dart @@ -1,5 +1,13 @@ import 'package:flutter/material.dart'; +import 'package:chat_flutter/model/user.dart'; class ProfileController with ChangeNotifier{ - + ProfileController(); + + Future getUserById(String userId) async { + User user = User(name: "test", imgUrl: ""); + + await Future.delayed(Duration(seconds: 1)); + return await Future.value(user); + } } \ No newline at end of file From 3cafa59048064a836880b5a6d192e825f4c20503 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 16:12:09 +0900 Subject: [PATCH 06/20] =?UTF-8?q?ProfileEditPage=E3=81=AEProvider=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/pages/main/profile/profile_edit.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ui/pages/main/profile/profile_edit.dart b/lib/ui/pages/main/profile/profile_edit.dart index 3372f8d..eabf6f4 100644 --- a/lib/ui/pages/main/profile/profile_edit.dart +++ b/lib/ui/pages/main/profile/profile_edit.dart @@ -1,7 +1,7 @@ +import 'package:chat_flutter/ui/pages/main/profile/profile_controller.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:chat_flutter/providers/user.dart'; import 'package:chat_flutter/ui/atoms/profile_image.dart'; import 'package:chat_flutter/ui/molecules/profile/app_bar.dart'; @@ -14,12 +14,12 @@ class ProfileEditPage extends StatelessWidget { const ProfileEditPage({Key key}) : super(key: key); @override Widget build(BuildContext context) { - final userProvider = Provider.of(context); + final _profileProvider = Provider.of(context); return Scaffold( appBar: ProfilePageAppBar(), backgroundColor: Colors.white, body: FutureBuilder( - future: userProvider.getUserById("userId"), + future: _profileProvider.getUserById("userId"), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); From 0cf5f175324dd78390f93b9ff59b96cc53167ee1 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 16:15:23 +0900 Subject: [PATCH 07/20] =?UTF-8?q?=E3=82=82=E3=82=8D=E3=82=82=E3=82=8D?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/profile/profile_controller.dart | 4 +++ lib/ui/pages/main/profile/profile_edit.dart | 2 ++ .../main/profile/profile_edit_controller.dart | 5 ---- lib/ui/pages/main/talk/talk.dart | 26 ------------------- 4 files changed, 6 insertions(+), 31 deletions(-) delete mode 100644 lib/ui/pages/main/profile/profile_edit_controller.dart diff --git a/lib/ui/pages/main/profile/profile_controller.dart b/lib/ui/pages/main/profile/profile_controller.dart index 2cfd1db..7c67473 100644 --- a/lib/ui/pages/main/profile/profile_controller.dart +++ b/lib/ui/pages/main/profile/profile_controller.dart @@ -10,4 +10,8 @@ class ProfileController with ChangeNotifier{ await Future.delayed(Duration(seconds: 1)); return await Future.value(user); } + + void changeProfileInfo(){ + //Firebaseへの変更通知 + } } \ No newline at end of file diff --git a/lib/ui/pages/main/profile/profile_edit.dart b/lib/ui/pages/main/profile/profile_edit.dart index eabf6f4..9d39bf0 100644 --- a/lib/ui/pages/main/profile/profile_edit.dart +++ b/lib/ui/pages/main/profile/profile_edit.dart @@ -53,6 +53,7 @@ class _ProfileEditPage extends StatelessWidget { const _ProfileEditPage({Key key, this.user}) : super(key: key); @override Widget build(BuildContext context) { + final _profileController = Provider.of(context,listen: false); final TextEditingController _nameController = TextEditingController( text: ModalRoute.of(context).settings.arguments, ); @@ -97,6 +98,7 @@ class _ProfileEditPage extends StatelessWidget { ), label: Text("更新する"), onPressed: () { + _profileController.changeProfileInfo(); Navigator.of(context).pop(); }, color: Colors.redAccent, diff --git a/lib/ui/pages/main/profile/profile_edit_controller.dart b/lib/ui/pages/main/profile/profile_edit_controller.dart deleted file mode 100644 index 62bb24e..0000000 --- a/lib/ui/pages/main/profile/profile_edit_controller.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:flutter/material.dart'; - -class ProfileEditController with ChangeNotifier{ - -} \ No newline at end of file diff --git a/lib/ui/pages/main/talk/talk.dart b/lib/ui/pages/main/talk/talk.dart index 9934025..0273689 100644 --- a/lib/ui/pages/main/talk/talk.dart +++ b/lib/ui/pages/main/talk/talk.dart @@ -47,30 +47,4 @@ class _TalkPageState extends State { }, ); } - - Future> _getRoomList() async { - final List roomList = [ - Room( - name: "Sport", - imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", - lastMessage: "hello,group!", - sendTime: "23:04", - ), - Room( - name: "Study", - imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", - lastMessage: "hey!", - sendTime: "21:04", - ), - Room( - name: "Hobby", - imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", - lastMessage: "amusement Park!!!!", - sendTime: "20:04", - ), - ]; - - await Future.delayed(Duration(seconds: 1)); - return await Future.value(roomList); - } } From abcd19715813de57c82ee8877a3bd7f2284b3d75 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 16:33:16 +0900 Subject: [PATCH 08/20] homeController --- lib/ui/pages/main/home/home.dart | 89 +++++++-------------- lib/ui/pages/main/home/home_controller.dart | 63 ++++++++++++++- 2 files changed, 93 insertions(+), 59 deletions(-) diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index 54bb2d9..eecff60 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -1,21 +1,46 @@ 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'; import 'package:flutter/material.dart'; import 'package:chat_flutter/model/user.dart'; import 'package:chat_flutter/model/group.dart'; import 'package:chat_flutter/config/app_text_size.dart'; +import 'package:provider/provider.dart'; class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { + final _homeController = Provider.of(context); return SingleChildScrollView( child: Column( children: [ - HomePageListTile( - name: 'name', - imgUrl: 'https://dot.asahi.com/S2000/upload/2019100100055_1.jpg', - isMe: true, + FutureBuilder( + future: _homeController.getMeById('test'), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } + switch (snapshot.connectionState) { + case ConnectionState.waiting: // データの取得まち + return Center( + child: CircularProgressIndicator(), + ); + + default: + if (snapshot.hasData) { + return HomePageListTile( + name: snapshot.data.name, + imgUrl: snapshot.data.imgUrl, + isMe: true, + ); + } else { + return Center( + child: Text("該当するユーザーがいません"), + ); + } + } + }, ), Container( constraints: BoxConstraints( @@ -46,7 +71,7 @@ class HomePage extends StatelessWidget { ), ), FutureBuilder( - future: _getGroupList(), + future: _homeController.getGroupList(), builder: ( BuildContext context, AsyncSnapshot> snapshot, @@ -120,7 +145,7 @@ class HomePage extends StatelessWidget { ), ), FutureBuilder( - future: _getFriendList(), + future: _homeController.getFriendList(), builder: ( BuildContext context, AsyncSnapshot> snapshot, @@ -185,56 +210,4 @@ class HomePage extends StatelessWidget { ), ); } - - Future> _getGroupList() async { - final List groupList = [ - Group( - name: "Sport", - imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", - ), - Group( - name: "Study", - imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", - ), - Group( - name: "Hobby", - imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", - ), - ]; - - await Future.delayed(Duration(seconds: 1)); - return await Future.value(groupList); - } - - Future> _getFriendList() async { - final List friendList = [ - User( - name: "Alex", - imgUrl: - "https://pbs.twimg.com/profile_images/581025665727655936/9CnwZZ6j.jpg", - isMe: false, - ), - User( - name: "Alex2(笑)", - imgUrl: - "https://pbs.twimg.com/profile_images/581025665727655936/9CnwZZ6j.jpg", - isMe: false, - ), - User( - name: "Jack", - imgUrl: - "https://pbs.twimg.com/profile_images/581025665727655936/9CnwZZ6j.jpg", - isMe: false, - ), - User( - name: "Brian", - imgUrl: - "https://pbs.twimg.com/profile_images/581025665727655936/9CnwZZ6j.jpg", - isMe: false, - ), - ]; - - await Future.delayed(Duration(seconds: 3)); - return await Future.value(friendList); - } } diff --git a/lib/ui/pages/main/home/home_controller.dart b/lib/ui/pages/main/home/home_controller.dart index 83c8456..1e480c5 100644 --- a/lib/ui/pages/main/home/home_controller.dart +++ b/lib/ui/pages/main/home/home_controller.dart @@ -1,5 +1,66 @@ +import 'package:chat_flutter/model/group.dart'; +import 'package:chat_flutter/model/user.dart'; import 'package:flutter/material.dart'; class HomeController with ChangeNotifier{ - + HomeController(); + + Future getMeById(String userId) async { + User user = User(name: "test", imgUrl: ""); + + await Future.delayed(Duration(seconds: 1)); + return await Future.value(user); + } + + Future> getGroupList() async { + final List groupList = [ + Group( + name: "Sport", + imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", + ), + Group( + name: "Study", + imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", + ), + Group( + name: "Hobby", + imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", + ), + ]; + + await Future.delayed(Duration(seconds: 1)); + return await Future.value(groupList); + } + + Future> getFriendList() async { + final List friendList = [ + User( + name: "Alex", + imgUrl: + "https://pbs.twimg.com/profile_images/581025665727655936/9CnwZZ6j.jpg", + isMe: false, + ), + User( + name: "Alex2(笑)", + imgUrl: + "https://pbs.twimg.com/profile_images/581025665727655936/9CnwZZ6j.jpg", + isMe: false, + ), + User( + name: "Jack", + imgUrl: + "https://pbs.twimg.com/profile_images/581025665727655936/9CnwZZ6j.jpg", + isMe: false, + ), + User( + name: "Brian", + imgUrl: + "https://pbs.twimg.com/profile_images/581025665727655936/9CnwZZ6j.jpg", + isMe: false, + ), + ]; + + await Future.delayed(Duration(seconds: 3)); + return await Future.value(friendList); + } } \ No newline at end of file From 9179ad54115f17234ce651b28730abd030435cf2 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 16:43:53 +0900 Subject: [PATCH 09/20] =?UTF-8?q?Provider=E3=82=92di.dart=E3=81=A7?= =?UTF-8?q?=E3=82=BB=E3=83=83=E3=83=88=EF=BC=88=E4=BB=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/di.dart | 16 ++++++++++++++++ lib/ui/pages/main/home/home_controller.dart | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/di.dart b/lib/di.dart index 9982adf..e00deab 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,4 +1,8 @@ import 'package:chat_flutter/providers/user.dart'; +import 'package:chat_flutter/ui/pages/main/home/home_controller.dart'; +import 'package:chat_flutter/ui/pages/main/main_controller.dart'; +import 'package:chat_flutter/ui/pages/main/profile/profile_controller.dart'; +import 'package:chat_flutter/ui/pages/main/talk/talk_controller.dart'; import 'package:provider/provider.dart'; import 'package:provider/single_child_widget.dart'; @@ -7,5 +11,17 @@ List get providers { ChangeNotifierProvider( create: (_) => UserProvider(), ), + ChangeNotifierProvider( + create: (_) => MainController(), + ), + ChangeNotifierProvider( + create: (_) => HomeController(), + ), + ChangeNotifierProvider( + create: (_) => TalkController(), + ), + ChangeNotifierProvider( + create: (_) => ProfileController(), + ), ]; } diff --git a/lib/ui/pages/main/home/home_controller.dart b/lib/ui/pages/main/home/home_controller.dart index 1e480c5..e2c44fe 100644 --- a/lib/ui/pages/main/home/home_controller.dart +++ b/lib/ui/pages/main/home/home_controller.dart @@ -6,7 +6,7 @@ class HomeController with ChangeNotifier{ HomeController(); Future getMeById(String userId) async { - User user = User(name: "test", imgUrl: ""); + User user = User(name: "test", imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg"); await Future.delayed(Duration(seconds: 1)); return await Future.value(user); From 02f1e31530fe6ca45f66f91528c6074989084f4c Mon Sep 17 00:00:00 2001 From: thoth000 Date: Sun, 12 Jul 2020 17:36:41 +0900 Subject: [PATCH 10/20] =?UTF-8?q?Future=E3=81=AE=E6=88=BB=E3=82=8A?= =?UTF-8?q?=E5=80=A4=E3=82=92void=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/pages/main/home/home.dart | 28 ++++++++++----------- lib/ui/pages/main/home/home_controller.dart | 22 ++++++++-------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index eecff60..12d7dd8 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -2,8 +2,6 @@ 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'; import 'package:flutter/material.dart'; -import 'package:chat_flutter/model/user.dart'; -import 'package:chat_flutter/model/group.dart'; import 'package:chat_flutter/config/app_text_size.dart'; import 'package:provider/provider.dart'; @@ -17,7 +15,7 @@ class HomePage extends StatelessWidget { children: [ FutureBuilder( future: _homeController.getMeById('test'), - builder: (BuildContext context, AsyncSnapshot snapshot) { + builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); } @@ -30,8 +28,8 @@ class HomePage extends StatelessWidget { default: if (snapshot.hasData) { return HomePageListTile( - name: snapshot.data.name, - imgUrl: snapshot.data.imgUrl, + name: _homeController.user.name, + imgUrl: _homeController.user.imgUrl, isMe: true, ); } else { @@ -74,10 +72,10 @@ class HomePage extends StatelessWidget { future: _homeController.getGroupList(), builder: ( BuildContext context, - AsyncSnapshot> snapshot, + AsyncSnapshot snapshot, ) { if (snapshot.hasData) { - if (snapshot.data.length != 0) { + if (_homeController.groupList.length != 0) { return Container( // ここのラップは適当にサイズ指定しているだけなので、レイアウトに合わせて変更する必要あり height: 220, @@ -92,14 +90,14 @@ class HomePage extends StatelessWidget { physics: ScrollPhysics(), scrollDirection: Axis.vertical, shrinkWrap: true, - itemCount: snapshot.data.length, + itemCount: _homeController.groupList.length, itemBuilder: ( BuildContext context, int index, ) { return HomePageListTile( - name: snapshot.data[index].name, - imgUrl: snapshot.data[index].imgUrl, + name: _homeController.groupList[index].name, + imgUrl: _homeController.groupList[index].imgUrl, ); }, ), @@ -148,10 +146,10 @@ class HomePage extends StatelessWidget { future: _homeController.getFriendList(), builder: ( BuildContext context, - AsyncSnapshot> snapshot, + AsyncSnapshot snapshot, ) { if (snapshot.hasData) { - if (snapshot.data.length != 0) { + if (_homeController.friendList.length != 0) { return Container( // ここのラップは適当にサイズ指定しているだけなので、レイアウトに合わせて変更する必要あり height: 220, @@ -166,14 +164,14 @@ class HomePage extends StatelessWidget { physics: ScrollPhysics(), scrollDirection: Axis.vertical, shrinkWrap: true, - itemCount: snapshot.data.length, + itemCount: _homeController.friendList.length, itemBuilder: ( BuildContext context, int index, ) { return HomePageListTile( - name: snapshot.data[index].name, - imgUrl: snapshot.data[index].imgUrl, + name: _homeController.friendList[index].name, + imgUrl: _homeController.friendList[index].imgUrl, ); }, ), diff --git a/lib/ui/pages/main/home/home_controller.dart b/lib/ui/pages/main/home/home_controller.dart index e2c44fe..f55f586 100644 --- a/lib/ui/pages/main/home/home_controller.dart +++ b/lib/ui/pages/main/home/home_controller.dart @@ -4,16 +4,18 @@ import 'package:flutter/material.dart'; class HomeController with ChangeNotifier{ HomeController(); - - Future getMeById(String userId) async { - User user = User(name: "test", imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg"); + User user; + List groupList; + List friendList; + Future getMeById(String userId) async { + user = User(name: "test", imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg"); await Future.delayed(Duration(seconds: 1)); - return await Future.value(user); + notifyListeners(); } - Future> getGroupList() async { - final List groupList = [ + Future getGroupList() async { + groupList = [ Group( name: "Sport", imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", @@ -29,11 +31,11 @@ class HomeController with ChangeNotifier{ ]; await Future.delayed(Duration(seconds: 1)); - return await Future.value(groupList); + notifyListeners(); } - Future> getFriendList() async { - final List friendList = [ + Future getFriendList() async { + friendList = [ User( name: "Alex", imgUrl: @@ -61,6 +63,6 @@ class HomeController with ChangeNotifier{ ]; await Future.delayed(Duration(seconds: 3)); - return await Future.value(friendList); + notifyListeners(); } } \ No newline at end of file From e41481ede67eb9599e213e0b9a2e0f78101a239b Mon Sep 17 00:00:00 2001 From: thoth000 Date: Mon, 13 Jul 2020 16:19:13 +0900 Subject: [PATCH 11/20] =?UTF-8?q?HomePage=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/di.dart | 3 - lib/ui/pages/main/home/home.dart | 257 +++++++++----------- lib/ui/pages/main/home/home_controller.dart | 18 +- lib/ui/pages/main/main.dart | 2 +- 4 files changed, 122 insertions(+), 158 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index e00deab..815c1c4 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -14,9 +14,6 @@ List get providers { ChangeNotifierProvider( create: (_) => MainController(), ), - ChangeNotifierProvider( - create: (_) => HomeController(), - ), ChangeNotifierProvider( create: (_) => TalkController(), ), diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index 12d7dd8..93bda37 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -7,39 +7,21 @@ import 'package:chat_flutter/config/app_text_size.dart'; import 'package:provider/provider.dart'; class HomePage extends StatelessWidget { + HomePage._({Key key}) : super(key:key); + + static Widget wrapped(){ + return ChangeNotifierProvider( + create: (_) => HomeController(), + child: HomePage._(), + ); + } + @override Widget build(BuildContext context) { - final _homeController = Provider.of(context); return SingleChildScrollView( child: Column( children: [ - FutureBuilder( - future: _homeController.getMeById('test'), - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); - } - switch (snapshot.connectionState) { - case ConnectionState.waiting: // データの取得まち - return Center( - child: CircularProgressIndicator(), - ); - - default: - if (snapshot.hasData) { - return HomePageListTile( - name: _homeController.user.name, - imgUrl: _homeController.user.imgUrl, - isMe: true, - ); - } else { - return Center( - child: Text("該当するユーザーがいません"), - ); - } - } - }, - ), + MyTile(), Container( constraints: BoxConstraints( minHeight: MediaQuery.of(context).size.height - 180, @@ -68,65 +50,7 @@ class HomePage extends StatelessWidget { ), ), ), - FutureBuilder( - future: _homeController.getGroupList(), - builder: ( - BuildContext context, - AsyncSnapshot snapshot, - ) { - if (snapshot.hasData) { - if (_homeController.groupList.length != 0) { - return Container( - // ここのラップは適当にサイズ指定しているだけなので、レイアウトに合わせて変更する必要あり - height: 220, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: AppSpace.small, - ), - ListView.builder( - physics: ScrollPhysics(), - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: _homeController.groupList.length, - itemBuilder: ( - BuildContext context, - int index, - ) { - return HomePageListTile( - name: _homeController.groupList[index].name, - imgUrl: _homeController.groupList[index].imgUrl, - ); - }, - ), - ], - ), - ), - ); - } else { - return Padding( - padding: EdgeInsets.only( - left: AppSpace.large, - top: AppSpace.small, - bottom: AppSpace.small, - ), - child: Text( - 'グループがありません', - ), - ); - } - } else if (snapshot.connectionState != - ConnectionState.done) { - return Center( - child: CircularProgressIndicator(), - ); - } else { - return Container(); - } - }, - ), + GroupTileList(), Divider( endIndent: AppSpace.big, ), @@ -142,65 +66,7 @@ class HomePage extends StatelessWidget { ), ), ), - FutureBuilder( - future: _homeController.getFriendList(), - builder: ( - BuildContext context, - AsyncSnapshot snapshot, - ) { - if (snapshot.hasData) { - if (_homeController.friendList.length != 0) { - return Container( - // ここのラップは適当にサイズ指定しているだけなので、レイアウトに合わせて変更する必要あり - height: 220, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: AppSpace.small, - ), - ListView.builder( - physics: ScrollPhysics(), - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: _homeController.friendList.length, - itemBuilder: ( - BuildContext context, - int index, - ) { - return HomePageListTile( - name: _homeController.friendList[index].name, - imgUrl: _homeController.friendList[index].imgUrl, - ); - }, - ), - ], - ), - ), - ); - } else { - return Padding( - padding: EdgeInsets.only( - left: AppSpace.large, - top: AppSpace.small, - bottom: AppSpace.small, - ), - child: Text( - '友達がいません', - ), - ); - } - } else if (snapshot.connectionState != - ConnectionState.done) { - return Center( - child: CircularProgressIndicator(), - ); - } else { - return Container(); - } - }, - ), + FriendTileList(), ], ), ), @@ -209,3 +75,102 @@ class HomePage extends StatelessWidget { ); } } + +class MyTile extends StatelessWidget { + @override + Widget build(BuildContext context) { + final _controller = Provider.of(context); + if (_controller.user == null) { + return Center( + child: CircularProgressIndicator(), + ); + } + return HomePageListTile( + name: _controller.user.name, + imgUrl: _controller.user.imgUrl, + isMe: true, + ); + } +} + +class GroupTileList extends StatelessWidget { + @override + Widget build(BuildContext context) { + final _controller = Provider.of(context); + if (_controller.groupList == null) { + return Center( + child: CircularProgressIndicator(), + ); + } + return Container( + height: 220, + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: AppSpace.small, + ), + ListView.builder( + physics: ScrollPhysics(), + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: _controller.groupList.length, + itemBuilder: ( + BuildContext context, + int index, + ) { + return HomePageListTile( + name: _controller.groupList[index].name, + imgUrl: _controller.groupList[index].imgUrl, + ); + }, + ), + ], + ), + ), + ); + } +} + +class FriendTileList extends StatelessWidget { + @override + Widget build(BuildContext context) { + final _controller = Provider.of(context); + if (_controller.friendList == null) { + return Center( + child: CircularProgressIndicator(), + ); + } else { + return Container( + // ここのラップは適当にサイズ指定しているだけなので、レイアウトに合わせて変更する必要あり + height: 220, + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: AppSpace.small, + ), + ListView.builder( + physics: ScrollPhysics(), + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: _controller.friendList.length, + itemBuilder: ( + BuildContext context, + int index, + ) { + return HomePageListTile( + name: _controller.friendList[index].name, + imgUrl: _controller.friendList[index].imgUrl, + ); + }, + ), + ], + ), + ), + ); + } + } +} diff --git a/lib/ui/pages/main/home/home_controller.dart b/lib/ui/pages/main/home/home_controller.dart index f55f586..67d1428 100644 --- a/lib/ui/pages/main/home/home_controller.dart +++ b/lib/ui/pages/main/home/home_controller.dart @@ -3,18 +3,21 @@ import 'package:chat_flutter/model/user.dart'; import 'package:flutter/material.dart'; class HomeController with ChangeNotifier{ - HomeController(); + HomeController(){ + getMeById("userId"); + getGroupList(); + getFriendList(); + } User user; List groupList; List friendList; - Future getMeById(String userId) async { + void getMeById(String userId) async { user = User(name: "test", imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg"); - await Future.delayed(Duration(seconds: 1)); notifyListeners(); } - Future getGroupList() async { + void getGroupList() async { groupList = [ Group( name: "Sport", @@ -30,11 +33,11 @@ class HomeController with ChangeNotifier{ ), ]; - await Future.delayed(Duration(seconds: 1)); + await Future.delayed(Duration(seconds: 5)); notifyListeners(); } - Future getFriendList() async { + void getFriendList() async { friendList = [ User( name: "Alex", @@ -61,8 +64,7 @@ class HomeController with ChangeNotifier{ isMe: false, ), ]; - - await Future.delayed(Duration(seconds: 3)); + await Future.delayed(Duration(seconds: 10)); notifyListeners(); } } \ No newline at end of file diff --git a/lib/ui/pages/main/main.dart b/lib/ui/pages/main/main.dart index f9b60fe..244b906 100644 --- a/lib/ui/pages/main/main.dart +++ b/lib/ui/pages/main/main.dart @@ -25,7 +25,7 @@ class MainPage extends StatelessWidget { ]; final List pages = [ - HomePage(), + HomePage.wrapped(), TalkPage(), ProfilePage(), ]; From 1ef3712a489de5a4d35f654dfcaedef166c61938 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Mon, 13 Jul 2020 16:27:21 +0900 Subject: [PATCH 12/20] MainController --- lib/di.dart | 5 ----- lib/main.dart | 2 +- lib/ui/pages/main/main.dart | 23 ++++++++++++++++------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index 815c1c4..9bf6da9 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,6 +1,4 @@ import 'package:chat_flutter/providers/user.dart'; -import 'package:chat_flutter/ui/pages/main/home/home_controller.dart'; -import 'package:chat_flutter/ui/pages/main/main_controller.dart'; import 'package:chat_flutter/ui/pages/main/profile/profile_controller.dart'; import 'package:chat_flutter/ui/pages/main/talk/talk_controller.dart'; import 'package:provider/provider.dart'; @@ -11,9 +9,6 @@ List get providers { ChangeNotifierProvider( create: (_) => UserProvider(), ), - ChangeNotifierProvider( - create: (_) => MainController(), - ), ChangeNotifierProvider( create: (_) => TalkController(), ), diff --git a/lib/main.dart b/lib/main.dart index 224777d..9297a4b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -32,7 +32,7 @@ class MyApp extends StatelessWidget { ), initialRoute: '/mainPage', routes: { - '/mainPage': (context) => MainPage(), + '/mainPage': (context) => MainPage.wrapped(), '/signUpPage': (context) => SignUpPage(), '/signInPage': (context) => SignInPage(), '/roomPage': (context) => RoomPage(), diff --git a/lib/ui/pages/main/main.dart b/lib/ui/pages/main/main.dart index 244b906..b572079 100644 --- a/lib/ui/pages/main/main.dart +++ b/lib/ui/pages/main/main.dart @@ -9,9 +9,18 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class MainPage extends StatelessWidget { + MainPage._({Key key}) : super(key:key); + + static Widget wrapped(){ + return new ChangeNotifierProvider( + create: (_) => MainController(), + child: MainPage._(), + ); + } + @override Widget build(BuildContext context) { - final _mainController = Provider.of(context); + final _controller = Provider.of(context); final List appBarList = [ HomePageAppBar(), TalkPageAppBar(), @@ -31,21 +40,21 @@ class MainPage extends StatelessWidget { ]; return Scaffold( - appBar: appBarList[_mainController.currentIndex], - backgroundColor: backgroundColor[_mainController.currentIndex], + appBar: appBarList[_controller.currentIndex], + backgroundColor: backgroundColor[_controller.currentIndex], bottomNavigationBar: bottomNavigation(context), - body: pages[_mainController.currentIndex], + body: pages[_controller.currentIndex], ); } Widget bottomNavigation(BuildContext context) { - final _mainController = Provider.of(context); + final _controller = Provider.of(context); return BottomNavigationBar( backgroundColor: Colors.white, type: BottomNavigationBarType.fixed, showSelectedLabels: false, showUnselectedLabels: false, - currentIndex: _mainController.currentIndex, + currentIndex: _controller.currentIndex, items: [ BottomNavigationBarItem( icon: Icon( @@ -73,7 +82,7 @@ class MainPage extends StatelessWidget { ), ], onTap: (index){ - _mainController.changePage(index); + _controller.changePage(index); } ); } From 4959e8ff9336c1175ccb2401c65c0856208380b7 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Mon, 13 Jul 2020 17:01:27 +0900 Subject: [PATCH 13/20] =?UTF-8?q?=E3=83=A1=E3=82=A4=E3=83=B3=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=81=AE=E3=82=B3=E3=83=B3=E3=83=88=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=83=A9=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/di.dart | 11 --- lib/main.dart | 7 +- lib/ui/pages/main/home/home.dart | 30 ++++----- lib/ui/pages/main/home/home_controller.dart | 2 +- lib/ui/pages/main/main.dart | 4 +- lib/ui/pages/main/profile/profile.dart | 44 +++++------- .../main/profile/profile_controller.dart | 14 ++-- lib/ui/pages/main/profile/profile_edit.dart | 36 +++------- lib/ui/pages/main/talk/talk.dart | 67 ++++++++----------- lib/ui/pages/main/talk/talk_controller.dart | 9 ++- 10 files changed, 87 insertions(+), 137 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index 9bf6da9..604fef5 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,19 +1,8 @@ import 'package:chat_flutter/providers/user.dart'; -import 'package:chat_flutter/ui/pages/main/profile/profile_controller.dart'; -import 'package:chat_flutter/ui/pages/main/talk/talk_controller.dart'; import 'package:provider/provider.dart'; import 'package:provider/single_child_widget.dart'; List get providers { return [ - ChangeNotifierProvider( - create: (_) => UserProvider(), - ), - ChangeNotifierProvider( - create: (_) => TalkController(), - ), - ChangeNotifierProvider( - create: (_) => ProfileController(), - ), ]; } diff --git a/lib/main.dart b/lib/main.dart index 9297a4b..7f8e224 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,10 +13,7 @@ import 'package:chat_flutter/ui/pages/sign_up.dart'; void main() { runApp( - MultiProvider( - providers: providers, - child: MyApp(), - ), + MyApp(), ); } @@ -36,7 +33,7 @@ class MyApp extends StatelessWidget { '/signUpPage': (context) => SignUpPage(), '/signInPage': (context) => SignInPage(), '/roomPage': (context) => RoomPage(), - '/profilePage': (context) => ProfilePage(), + '/profilePage': (context) => ProfilePage.wrapped(), '/profileEditPage': (context) => ProfileEditPage(), '/addFriendPage': (context) => AddFriendPage(), '/createGroupPage': (context) => CreateGroupPage(), diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index 93bda37..0c6fac7 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -10,7 +10,7 @@ class HomePage extends StatelessWidget { HomePage._({Key key}) : super(key:key); static Widget wrapped(){ - return ChangeNotifierProvider( + return new ChangeNotifierProvider( create: (_) => HomeController(), child: HomePage._(), ); @@ -79,15 +79,15 @@ class HomePage extends StatelessWidget { class MyTile extends StatelessWidget { @override Widget build(BuildContext context) { - final _controller = Provider.of(context); - if (_controller.user == null) { + final _user = Provider.of(context).user; + if (_user == null) { return Center( child: CircularProgressIndicator(), ); } return HomePageListTile( - name: _controller.user.name, - imgUrl: _controller.user.imgUrl, + name: _user.name, + imgUrl: _user.imgUrl, isMe: true, ); } @@ -96,8 +96,8 @@ class MyTile extends StatelessWidget { class GroupTileList extends StatelessWidget { @override Widget build(BuildContext context) { - final _controller = Provider.of(context); - if (_controller.groupList == null) { + final _groupList = Provider.of(context).groupList; + if (_groupList == null) { return Center( child: CircularProgressIndicator(), ); @@ -115,14 +115,14 @@ class GroupTileList extends StatelessWidget { physics: ScrollPhysics(), scrollDirection: Axis.vertical, shrinkWrap: true, - itemCount: _controller.groupList.length, + itemCount: _groupList.length, itemBuilder: ( BuildContext context, int index, ) { return HomePageListTile( - name: _controller.groupList[index].name, - imgUrl: _controller.groupList[index].imgUrl, + name: _groupList[index].name, + imgUrl: _groupList[index].imgUrl, ); }, ), @@ -136,8 +136,8 @@ class GroupTileList extends StatelessWidget { class FriendTileList extends StatelessWidget { @override Widget build(BuildContext context) { - final _controller = Provider.of(context); - if (_controller.friendList == null) { + final _friendList = Provider.of(context).friendList; + if (_friendList == null) { return Center( child: CircularProgressIndicator(), ); @@ -156,14 +156,14 @@ class FriendTileList extends StatelessWidget { physics: ScrollPhysics(), scrollDirection: Axis.vertical, shrinkWrap: true, - itemCount: _controller.friendList.length, + itemCount: _friendList.length, itemBuilder: ( BuildContext context, int index, ) { return HomePageListTile( - name: _controller.friendList[index].name, - imgUrl: _controller.friendList[index].imgUrl, + name: _friendList[index].name, + imgUrl: _friendList[index].imgUrl, ); }, ), diff --git a/lib/ui/pages/main/home/home_controller.dart b/lib/ui/pages/main/home/home_controller.dart index 67d1428..c44f222 100644 --- a/lib/ui/pages/main/home/home_controller.dart +++ b/lib/ui/pages/main/home/home_controller.dart @@ -11,6 +11,7 @@ class HomeController with ChangeNotifier{ User user; List groupList; List friendList; + void getMeById(String userId) async { user = User(name: "test", imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg"); await Future.delayed(Duration(seconds: 1)); @@ -32,7 +33,6 @@ class HomeController with ChangeNotifier{ imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", ), ]; - await Future.delayed(Duration(seconds: 5)); notifyListeners(); } diff --git a/lib/ui/pages/main/main.dart b/lib/ui/pages/main/main.dart index b572079..eadcfa4 100644 --- a/lib/ui/pages/main/main.dart +++ b/lib/ui/pages/main/main.dart @@ -35,8 +35,8 @@ class MainPage extends StatelessWidget { final List pages = [ HomePage.wrapped(), - TalkPage(), - ProfilePage(), + TalkPage.wrapped(), + ProfilePage.wrapped(), ]; return Scaffold( diff --git a/lib/ui/pages/main/profile/profile.dart b/lib/ui/pages/main/profile/profile.dart index 06f3445..8eeb527 100644 --- a/lib/ui/pages/main/profile/profile.dart +++ b/lib/ui/pages/main/profile/profile.dart @@ -9,36 +9,26 @@ import 'package:chat_flutter/model/user.dart'; import 'package:chat_flutter/config/app_text_size.dart'; class ProfilePage extends StatelessWidget { - const ProfilePage({Key key}) : super(key: key); - @override - Widget build(BuildContext context) { - final _profileController = Provider.of(context); - return FutureBuilder( - future: _profileController.getUserById("userId"), - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); - } - switch (snapshot.connectionState) { - case ConnectionState.waiting: // データの取得まち - return Center( - child: CircularProgressIndicator(), - ); + const ProfilePage._({Key key}) : super(key: key); - default: - if (snapshot.hasData) { - return _ProfilePage( - user: snapshot.data, - ); - } else { - return Center( - child: Text("該当するユーザーがいません"), - ); - } - } - }, + static Widget wrapped() { + return ChangeNotifierProvider( + create: (_) => ProfileController(), + child: ProfilePage._(), ); } + + @override + Widget build(BuildContext context) { + final _user = Provider.of(context).user; + if (_user == null) { + return Center( + child: CircularProgressIndicator(), + ); + } else { + return _ProfilePage(user: _user); + } + } } class _ProfilePage extends StatelessWidget { diff --git a/lib/ui/pages/main/profile/profile_controller.dart b/lib/ui/pages/main/profile/profile_controller.dart index 7c67473..4c7ac97 100644 --- a/lib/ui/pages/main/profile/profile_controller.dart +++ b/lib/ui/pages/main/profile/profile_controller.dart @@ -2,16 +2,18 @@ import 'package:flutter/material.dart'; import 'package:chat_flutter/model/user.dart'; class ProfileController with ChangeNotifier{ - ProfileController(); - - Future getUserById(String userId) async { - User user = User(name: "test", imgUrl: ""); + ProfileController(){ + getUserById("testId"); + } + User user; + void getUserById(String userId) async { + user = User(name: "test", imgUrl: ""); await Future.delayed(Duration(seconds: 1)); - return await Future.value(user); + notifyListeners(); } - void changeProfileInfo(){ + void changeProfileInfo() async{ //Firebaseへの変更通知 } } \ No newline at end of file diff --git a/lib/ui/pages/main/profile/profile_edit.dart b/lib/ui/pages/main/profile/profile_edit.dart index 9d39bf0..4c467da 100644 --- a/lib/ui/pages/main/profile/profile_edit.dart +++ b/lib/ui/pages/main/profile/profile_edit.dart @@ -14,35 +14,17 @@ class ProfileEditPage extends StatelessWidget { const ProfileEditPage({Key key}) : super(key: key); @override Widget build(BuildContext context) { - final _profileProvider = Provider.of(context); + final _user = Provider.of(context, listen: false).user; return Scaffold( appBar: ProfilePageAppBar(), backgroundColor: Colors.white, - body: FutureBuilder( - future: _profileProvider.getUserById("userId"), - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasError) { - return Text('Error: ${snapshot.error}'); - } - switch (snapshot.connectionState) { - case ConnectionState.waiting: // データの取得まち - return Center( - child: CircularProgressIndicator(), - ); - - default: - if (snapshot.hasData) { - return _ProfileEditPage( - user: snapshot.data, - ); - } else { - return Center( - child: Text("該当するユーザーがいません"), - ); - } - } - }, - ), + body: (_user == null) + ? Center( + child: CircularProgressIndicator(), + ) + : _ProfileEditPage( + user: _user, + ), ); } } @@ -53,7 +35,7 @@ class _ProfileEditPage extends StatelessWidget { const _ProfileEditPage({Key key, this.user}) : super(key: key); @override Widget build(BuildContext context) { - final _profileController = Provider.of(context,listen: false); + final _profileController = Provider.of(context, listen: false); final TextEditingController _nameController = TextEditingController( text: ModalRoute.of(context).settings.arguments, ); diff --git a/lib/ui/pages/main/talk/talk.dart b/lib/ui/pages/main/talk/talk.dart index 0273689..1f844bc 100644 --- a/lib/ui/pages/main/talk/talk.dart +++ b/lib/ui/pages/main/talk/talk.dart @@ -1,50 +1,37 @@ import 'package:chat_flutter/ui/molecules/talk/list_tile.dart'; import 'package:chat_flutter/ui/pages/main/talk/talk_controller.dart'; import 'package:flutter/material.dart'; -import 'package:chat_flutter/model/room.dart'; import 'package:provider/provider.dart'; -class TalkPage extends StatefulWidget { - @override - _TalkPageState createState() => _TalkPageState(); -} +class TalkPage extends StatelessWidget { + TalkPage._({Key key}) : super(key:key); -class _TalkPageState extends State { + static Widget wrapped(){ + return ChangeNotifierProvider( + create: (_) => TalkController(), + child: TalkPage._(), + ); + } @override Widget build(BuildContext context) { - final _talkController = Provider.of(context); - return FutureBuilder( - future: _talkController.getRoomList(), - builder: ( - BuildContext context, - AsyncSnapshot> snapshot, - ) { - if (snapshot.hasData) { - if (snapshot.data.length != 0) { - return ListView.builder( - physics: ScrollPhysics(), - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: snapshot.data.length, - itemBuilder: ( - BuildContext context, - int index, - ) { - return TalkPageListTile(snapshot.data[index]); - }); - } else { - return Center( - child: Text("トークルームがありません"), - ); - } - } else if (snapshot.connectionState != ConnectionState.done) { - return Center( - child: CircularProgressIndicator(), - ); - } else { - return Container(); - } - }, - ); + final _roomList = Provider.of(context).roomList; + if (_roomList == null) { + return Center( + child: CircularProgressIndicator(), + ); + } else { + return ListView.builder( + physics: ScrollPhysics(), + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: _roomList.length, + itemBuilder: ( + BuildContext context, + int index, + ) { + return TalkPageListTile(_roomList[index]); + }, + ); + } } } diff --git a/lib/ui/pages/main/talk/talk_controller.dart b/lib/ui/pages/main/talk/talk_controller.dart index 508e3a4..903b95d 100644 --- a/lib/ui/pages/main/talk/talk_controller.dart +++ b/lib/ui/pages/main/talk/talk_controller.dart @@ -2,7 +2,11 @@ import 'package:flutter/material.dart'; import 'package:chat_flutter/model/room.dart'; class TalkController with ChangeNotifier{ - Future> getRoomList() async { + TalkController(){ + getRoomList(); + } + List roomList; + void getRoomList() async { final List roomList = [ Room( name: "Sport", @@ -23,8 +27,7 @@ class TalkController with ChangeNotifier{ sendTime: "20:04", ), ]; - await Future.delayed(Duration(seconds: 1)); - return await Future.value(roomList); + notifyListeners(); } } \ No newline at end of file From 52cdb0c96851d2de18e37d4c943d3b4e42f399df Mon Sep 17 00:00:00 2001 From: thoth000 Date: Mon, 13 Jul 2020 18:24:12 +0900 Subject: [PATCH 14/20] =?UTF-8?q?MultiProvider=E3=82=92main=E3=81=A7?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MainページとしてHome,Talk,Profileは一体なのでMultiProviderとして4つのモデルを定義した。 --- lib/di.dart | 2 -- lib/main.dart | 6 +---- lib/ui/pages/main/home/home.dart | 10 +------- lib/ui/pages/main/main.dart | 26 +++++++++++++++++---- lib/ui/pages/main/profile/profile.dart | 10 +------- lib/ui/pages/main/profile/profile_edit.dart | 10 +++++++- lib/ui/pages/main/talk/talk.dart | 9 +------ lib/ui/pages/main/talk/talk_controller.dart | 2 +- 8 files changed, 35 insertions(+), 40 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index 604fef5..eaa8ce2 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,5 +1,3 @@ -import 'package:chat_flutter/providers/user.dart'; -import 'package:provider/provider.dart'; import 'package:provider/single_child_widget.dart'; List get providers { diff --git a/lib/main.dart b/lib/main.dart index 7f8e224..6773abf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,12 +1,9 @@ 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/main.dart'; import 'package:chat_flutter/ui/pages/main/profile/profile_edit.dart'; -import 'package:chat_flutter/ui/pages/main/profile/profile.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'; @@ -33,8 +30,7 @@ class MyApp extends StatelessWidget { '/signUpPage': (context) => SignUpPage(), '/signInPage': (context) => SignInPage(), '/roomPage': (context) => RoomPage(), - '/profilePage': (context) => ProfilePage.wrapped(), - '/profileEditPage': (context) => ProfileEditPage(), + '/profileEditPage': (context) => ProfileEditPage.wrapped(), '/addFriendPage': (context) => AddFriendPage(), '/createGroupPage': (context) => CreateGroupPage(), }, diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index 0c6fac7..7d3348a 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -7,15 +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); - - static Widget wrapped(){ - return new ChangeNotifierProvider( - create: (_) => HomeController(), - child: HomePage._(), - ); - } - + HomePage({Key key}) : super(key:key); @override Widget build(BuildContext context) { return SingleChildScrollView( diff --git a/lib/ui/pages/main/main.dart b/lib/ui/pages/main/main.dart index eadcfa4..682e8b9 100644 --- a/lib/ui/pages/main/main.dart +++ b/lib/ui/pages/main/main.dart @@ -2,9 +2,12 @@ import 'package:chat_flutter/ui/molecules/home/app_bar.dart'; import 'package:chat_flutter/ui/molecules/profile/app_bar.dart'; import 'package:chat_flutter/ui/molecules/talk/app_bar.dart'; import 'package:chat_flutter/ui/pages/main/home/home.dart'; +import 'package:chat_flutter/ui/pages/main/home/home_controller.dart'; import 'package:chat_flutter/ui/pages/main/main_controller.dart'; import 'package:chat_flutter/ui/pages/main/profile/profile.dart'; +import 'package:chat_flutter/ui/pages/main/profile/profile_controller.dart'; import 'package:chat_flutter/ui/pages/main/talk/talk.dart'; +import 'package:chat_flutter/ui/pages/main/talk/talk_controller.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -12,8 +15,21 @@ class MainPage extends StatelessWidget { MainPage._({Key key}) : super(key:key); static Widget wrapped(){ - return new ChangeNotifierProvider( - create: (_) => MainController(), + return MultiProvider( + providers:[ + ChangeNotifierProvider( + create: (_) => MainController(), + ), + ChangeNotifierProvider( + create: (_) => HomeController(), + ), + ChangeNotifierProvider( + create: (_) => TalkController(), + ), + ChangeNotifierProvider( + create: (_) => ProfileController(), + ), + ], child: MainPage._(), ); } @@ -34,9 +50,9 @@ class MainPage extends StatelessWidget { ]; final List pages = [ - HomePage.wrapped(), - TalkPage.wrapped(), - ProfilePage.wrapped(), + HomePage(), + TalkPage(), + ProfilePage(), ]; return Scaffold( diff --git a/lib/ui/pages/main/profile/profile.dart b/lib/ui/pages/main/profile/profile.dart index 8eeb527..a1f66f9 100644 --- a/lib/ui/pages/main/profile/profile.dart +++ b/lib/ui/pages/main/profile/profile.dart @@ -9,15 +9,7 @@ import 'package:chat_flutter/model/user.dart'; import 'package:chat_flutter/config/app_text_size.dart'; class ProfilePage extends StatelessWidget { - const ProfilePage._({Key key}) : super(key: key); - - static Widget wrapped() { - return ChangeNotifierProvider( - create: (_) => ProfileController(), - child: ProfilePage._(), - ); - } - + const ProfilePage({Key key}) : super(key: key); @override Widget build(BuildContext context) { final _user = Provider.of(context).user; diff --git a/lib/ui/pages/main/profile/profile_edit.dart b/lib/ui/pages/main/profile/profile_edit.dart index 4c467da..ccf55b4 100644 --- a/lib/ui/pages/main/profile/profile_edit.dart +++ b/lib/ui/pages/main/profile/profile_edit.dart @@ -11,7 +11,15 @@ import 'package:chat_flutter/config/app_space.dart'; import 'package:chat_flutter/config/app_text_size.dart'; class ProfileEditPage extends StatelessWidget { - const ProfileEditPage({Key key}) : super(key: key); + const ProfileEditPage._({Key key}) : super(key: key); + + static Widget wrapped(){ + return ChangeNotifierProvider( + create: (_) => ProfileController(), + child: ProfileEditPage._(), + ); + } + @override Widget build(BuildContext context) { final _user = Provider.of(context, listen: false).user; diff --git a/lib/ui/pages/main/talk/talk.dart b/lib/ui/pages/main/talk/talk.dart index 1f844bc..18bdc38 100644 --- a/lib/ui/pages/main/talk/talk.dart +++ b/lib/ui/pages/main/talk/talk.dart @@ -4,14 +4,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class TalkPage extends StatelessWidget { - TalkPage._({Key key}) : super(key:key); - - static Widget wrapped(){ - return ChangeNotifierProvider( - create: (_) => TalkController(), - child: TalkPage._(), - ); - } + TalkPage({Key key}) : super(key:key); @override Widget build(BuildContext context) { final _roomList = Provider.of(context).roomList; diff --git a/lib/ui/pages/main/talk/talk_controller.dart b/lib/ui/pages/main/talk/talk_controller.dart index 903b95d..a2f9114 100644 --- a/lib/ui/pages/main/talk/talk_controller.dart +++ b/lib/ui/pages/main/talk/talk_controller.dart @@ -7,7 +7,7 @@ class TalkController with ChangeNotifier{ } List roomList; void getRoomList() async { - final List roomList = [ + roomList = [ Room( name: "Sport", imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", From 53080e95d1c011b5aafb337a8316a91e54a7fff3 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Mon, 13 Jul 2020 18:35:49 +0900 Subject: [PATCH 15/20] flutter format . --- lib/di.dart | 3 +- lib/ui/pages/main/home/home.dart | 2 +- lib/ui/pages/main/home/home_controller.dart | 10 +-- lib/ui/pages/main/main.dart | 69 +++++++++---------- lib/ui/pages/main/main_controller.dart | 8 +-- lib/ui/pages/main/profile/profile.dart | 2 +- .../main/profile/profile_controller.dart | 10 +-- lib/ui/pages/main/profile/profile_edit.dart | 11 +-- lib/ui/pages/main/talk/talk.dart | 2 +- lib/ui/pages/main/talk/talk_controller.dart | 6 +- 10 files changed, 63 insertions(+), 60 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index eaa8ce2..6adbc69 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,6 +1,5 @@ import 'package:provider/single_child_widget.dart'; List get providers { - return [ - ]; + return []; } diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index 7d3348a..b6af511 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -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); @override Widget build(BuildContext context) { return SingleChildScrollView( diff --git a/lib/ui/pages/main/home/home_controller.dart b/lib/ui/pages/main/home/home_controller.dart index c44f222..224f2f9 100644 --- a/lib/ui/pages/main/home/home_controller.dart +++ b/lib/ui/pages/main/home/home_controller.dart @@ -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 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"); await Future.delayed(Duration(seconds: 1)); notifyListeners(); } @@ -67,4 +69,4 @@ class HomeController with ChangeNotifier{ await Future.delayed(Duration(seconds: 10)); notifyListeners(); } -} \ No newline at end of file +} diff --git a/lib/ui/pages/main/main.dart b/lib/ui/pages/main/main.dart index 682e8b9..7afc634 100644 --- a/lib/ui/pages/main/main.dart +++ b/lib/ui/pages/main/main.dart @@ -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( create: (_) => MainController(), ), @@ -66,40 +66,39 @@ class MainPage extends StatelessWidget { Widget bottomNavigation(BuildContext context) { final _controller = Provider.of(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( + 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); + }); } } diff --git a/lib/ui/pages/main/main_controller.dart b/lib/ui/pages/main/main_controller.dart index 1de3614..37f7058 100644 --- a/lib/ui/pages/main/main_controller.dart +++ b/lib/ui/pages/main/main_controller.dart @@ -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(); } -} \ No newline at end of file +} diff --git a/lib/ui/pages/main/profile/profile.dart b/lib/ui/pages/main/profile/profile.dart index a1f66f9..e9f281a 100644 --- a/lib/ui/pages/main/profile/profile.dart +++ b/lib/ui/pages/main/profile/profile.dart @@ -61,7 +61,7 @@ class _ProfilePage extends StatelessWidget { Navigator.pushNamed( context, "/profileEditPage", - arguments: "test", + arguments: user.name, ); }, color: Colors.green, diff --git a/lib/ui/pages/main/profile/profile_controller.dart b/lib/ui/pages/main/profile/profile_controller.dart index 4c7ac97..3fbe95e 100644 --- a/lib/ui/pages/main/profile/profile_controller.dart +++ b/lib/ui/pages/main/profile/profile_controller.dart @@ -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; @@ -13,7 +14,8 @@ class ProfileController with ChangeNotifier{ notifyListeners(); } - void changeProfileInfo() async{ + void changeProfileInfo(String s) async { //Firebaseへの変更通知 + print(s); } -} \ No newline at end of file +} diff --git a/lib/ui/pages/main/profile/profile_edit.dart b/lib/ui/pages/main/profile/profile_edit.dart index ccf55b4..b4d2902 100644 --- a/lib/ui/pages/main/profile/profile_edit.dart +++ b/lib/ui/pages/main/profile/profile_edit.dart @@ -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( create: (_) => ProfileController(), child: ProfileEditPage._(), @@ -22,7 +22,7 @@ class ProfileEditPage extends StatelessWidget { @override Widget build(BuildContext context) { - final _user = Provider.of(context, listen: false).user; + final _user = Provider.of(context).user; return Scaffold( appBar: ProfilePageAppBar(), backgroundColor: Colors.white, @@ -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(context, listen: false); + final _profileController = + Provider.of(context, listen: false); final TextEditingController _nameController = TextEditingController( text: ModalRoute.of(context).settings.arguments, ); @@ -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, diff --git a/lib/ui/pages/main/talk/talk.dart b/lib/ui/pages/main/talk/talk.dart index 18bdc38..e86ecd9 100644 --- a/lib/ui/pages/main/talk/talk.dart +++ b/lib/ui/pages/main/talk/talk.dart @@ -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(context).roomList; diff --git a/lib/ui/pages/main/talk/talk_controller.dart b/lib/ui/pages/main/talk/talk_controller.dart index a2f9114..1067e61 100644 --- a/lib/ui/pages/main/talk/talk_controller.dart +++ b/lib/ui/pages/main/talk/talk_controller.dart @@ -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 roomList; @@ -30,4 +30,4 @@ class TalkController with ChangeNotifier{ await Future.delayed(Duration(seconds: 1)); notifyListeners(); } -} \ No newline at end of file +} From 61ce4a2370cf3565b23c29516741bda7a2afef3a Mon Sep 17 00:00:00 2001 From: thoth000 Date: Mon, 13 Jul 2020 19:22:15 +0900 Subject: [PATCH 16/20] =?UTF-8?q?=E4=BD=BF=E3=82=8F=E3=81=AA=E3=81=84di.da?= =?UTF-8?q?rt=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/di.dart | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 lib/di.dart diff --git a/lib/di.dart b/lib/di.dart deleted file mode 100644 index 6adbc69..0000000 --- a/lib/di.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:provider/single_child_widget.dart'; - -List get providers { - return []; -} From 7c87aa96d33fb970c518b7f1974e4b2d11e9f372 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Wed, 15 Jul 2020 19:26:34 +0900 Subject: [PATCH 17/20] =?UTF-8?q?=E6=8C=87=E6=91=98=E9=83=A8=E5=88=86?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/pages/main/home/home.dart | 47 ++++++++++----------- lib/ui/pages/main/home/home_controller.dart | 9 ++-- lib/ui/pages/main/main.dart | 20 ++++----- lib/ui/pages/main/profile/profile.dart | 11 +++-- lib/ui/pages/main/profile/profile_edit.dart | 12 +++--- lib/ui/pages/main/talk/talk.dart | 11 +++-- 6 files changed, 54 insertions(+), 56 deletions(-) diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index b6af511..4aba515 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -7,13 +7,12 @@ import 'package:chat_flutter/config/app_text_size.dart'; import 'package:provider/provider.dart'; class HomePage extends StatelessWidget { - HomePage({Key key}) : super(key: key); @override Widget build(BuildContext context) { return SingleChildScrollView( child: Column( children: [ - MyTile(), + _MyTile(), Container( constraints: BoxConstraints( minHeight: MediaQuery.of(context).size.height - 180, @@ -42,7 +41,7 @@ class HomePage extends StatelessWidget { ), ), ), - GroupTileList(), + _GroupTileList(), Divider( endIndent: AppSpace.big, ), @@ -58,7 +57,7 @@ class HomePage extends StatelessWidget { ), ), ), - FriendTileList(), + _FriendTileList(), ], ), ), @@ -68,29 +67,29 @@ class HomePage extends StatelessWidget { } } -class MyTile extends StatelessWidget { +class _MyTile extends StatelessWidget { @override Widget build(BuildContext context) { - final _user = Provider.of(context).user; - if (_user == null) { - return Center( + final user = Provider.of(context).user; + if (user == null) { + return const Center( child: CircularProgressIndicator(), ); } return HomePageListTile( - name: _user.name, - imgUrl: _user.imgUrl, + name: user.name, + imgUrl: user.imgUrl, isMe: true, ); } } -class GroupTileList extends StatelessWidget { +class _GroupTileList extends StatelessWidget { @override Widget build(BuildContext context) { - final _groupList = Provider.of(context).groupList; - if (_groupList == null) { - return Center( + final groupList = Provider.of(context).groupList; + if (groupList == null) { + return const Center( child: CircularProgressIndicator(), ); } @@ -107,14 +106,14 @@ class GroupTileList extends StatelessWidget { physics: ScrollPhysics(), scrollDirection: Axis.vertical, shrinkWrap: true, - itemCount: _groupList.length, + itemCount: groupList.length, itemBuilder: ( BuildContext context, int index, ) { return HomePageListTile( - name: _groupList[index].name, - imgUrl: _groupList[index].imgUrl, + name: groupList[index].name, + imgUrl: groupList[index].imgUrl, ); }, ), @@ -125,12 +124,12 @@ class GroupTileList extends StatelessWidget { } } -class FriendTileList extends StatelessWidget { +class _FriendTileList extends StatelessWidget { @override Widget build(BuildContext context) { - final _friendList = Provider.of(context).friendList; - if (_friendList == null) { - return Center( + final friendList = Provider.of(context).friendList; + if (friendList == null) { + return const Center( child: CircularProgressIndicator(), ); } else { @@ -148,14 +147,14 @@ class FriendTileList extends StatelessWidget { physics: ScrollPhysics(), scrollDirection: Axis.vertical, shrinkWrap: true, - itemCount: _friendList.length, + itemCount: friendList.length, itemBuilder: ( BuildContext context, int index, ) { return HomePageListTile( - name: _friendList[index].name, - imgUrl: _friendList[index].imgUrl, + name: friendList[index].name, + imgUrl: friendList[index].imgUrl, ); }, ), diff --git a/lib/ui/pages/main/home/home_controller.dart b/lib/ui/pages/main/home/home_controller.dart index 224f2f9..ae9546f 100644 --- a/lib/ui/pages/main/home/home_controller.dart +++ b/lib/ui/pages/main/home/home_controller.dart @@ -14,8 +14,9 @@ class HomeController with ChangeNotifier { void getMeById(String userId) async { user = User( - name: "test", - imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg"); + name: "test", + imgUrl: "https://dot.asahi.com/S2000/upload/2019100100055_1.jpg", + ); await Future.delayed(Duration(seconds: 1)); notifyListeners(); } @@ -35,7 +36,7 @@ class HomeController with ChangeNotifier { imgUrl: "https://prtimes.jp/i/24101/70/resize/d24101-70-320114-0.jpg", ), ]; - await Future.delayed(Duration(seconds: 5)); + await Future.delayed(Duration(seconds: 3)); notifyListeners(); } @@ -66,7 +67,7 @@ class HomeController with ChangeNotifier { isMe: false, ), ]; - await Future.delayed(Duration(seconds: 10)); + await Future.delayed(Duration(seconds: 5)); notifyListeners(); } } diff --git a/lib/ui/pages/main/main.dart b/lib/ui/pages/main/main.dart index 7afc634..275dfcd 100644 --- a/lib/ui/pages/main/main.dart +++ b/lib/ui/pages/main/main.dart @@ -36,7 +36,7 @@ class MainPage extends StatelessWidget { @override Widget build(BuildContext context) { - final _controller = Provider.of(context); + final controller = Provider.of(context); final List appBarList = [ HomePageAppBar(), TalkPageAppBar(), @@ -56,22 +56,22 @@ class MainPage extends StatelessWidget { ]; return Scaffold( - appBar: appBarList[_controller.currentIndex], - backgroundColor: backgroundColor[_controller.currentIndex], - bottomNavigationBar: bottomNavigation(context), - body: pages[_controller.currentIndex], + appBar: appBarList[controller.currentIndex], + backgroundColor: backgroundColor[controller.currentIndex], + bottomNavigationBar: _bottomNavigation(context), + body: pages[controller.currentIndex], ); } - Widget bottomNavigation(BuildContext context) { - final _controller = Provider.of(context); + Widget _bottomNavigation(BuildContext context) { + final controller = Provider.of(context); return BottomNavigationBar( backgroundColor: Colors.white, type: BottomNavigationBarType.fixed, showSelectedLabels: false, showUnselectedLabels: false, - currentIndex: _controller.currentIndex, - items: [ + currentIndex: controller.currentIndex, + items: const [ BottomNavigationBarItem( icon: Icon( Icons.home, @@ -98,7 +98,7 @@ class MainPage extends StatelessWidget { ), ], onTap: (index) { - _controller.changePage(index); + controller.changePage(index); }); } } diff --git a/lib/ui/pages/main/profile/profile.dart b/lib/ui/pages/main/profile/profile.dart index e9f281a..667aae7 100644 --- a/lib/ui/pages/main/profile/profile.dart +++ b/lib/ui/pages/main/profile/profile.dart @@ -9,16 +9,15 @@ import 'package:chat_flutter/model/user.dart'; import 'package:chat_flutter/config/app_text_size.dart'; class ProfilePage extends StatelessWidget { - const ProfilePage({Key key}) : super(key: key); @override Widget build(BuildContext context) { - final _user = Provider.of(context).user; - if (_user == null) { - return Center( + final user = Provider.of(context).user; + if (user == null) { + return const Center( child: CircularProgressIndicator(), ); } else { - return _ProfilePage(user: _user); + return _ProfilePage(user: user); } } } @@ -56,7 +55,7 @@ class _ProfilePage extends StatelessWidget { Icons.edit, color: Colors.white, ), - label: Text("編集する"), + label: const Text("編集する"), onPressed: () { Navigator.pushNamed( context, diff --git a/lib/ui/pages/main/profile/profile_edit.dart b/lib/ui/pages/main/profile/profile_edit.dart index b4d2902..a34bf4a 100644 --- a/lib/ui/pages/main/profile/profile_edit.dart +++ b/lib/ui/pages/main/profile/profile_edit.dart @@ -22,16 +22,16 @@ class ProfileEditPage extends StatelessWidget { @override Widget build(BuildContext context) { - final _user = Provider.of(context).user; + final user = Provider.of(context).user; return Scaffold( appBar: ProfilePageAppBar(), backgroundColor: Colors.white, - body: (_user == null) + body: (user == null) ? Center( child: CircularProgressIndicator(), ) : _ProfileEditPage( - user: _user, + user: user, ), ); } @@ -43,7 +43,7 @@ class _ProfileEditPage extends StatelessWidget { const _ProfileEditPage({Key key, this.user}) : super(key: key); @override Widget build(BuildContext context) { - final _profileController = + final profileController = Provider.of(context, listen: false); final TextEditingController _nameController = TextEditingController( text: ModalRoute.of(context).settings.arguments, @@ -87,9 +87,9 @@ class _ProfileEditPage extends StatelessWidget { Icons.arrow_upward, color: Colors.white, ), - label: Text("更新する"), + label: const Text("更新する"), onPressed: () async { - _profileController.changeProfileInfo(_nameController.text); + profileController.changeProfileInfo(_nameController.text); Navigator.of(context).pop(); }, color: Colors.redAccent, diff --git a/lib/ui/pages/main/talk/talk.dart b/lib/ui/pages/main/talk/talk.dart index e86ecd9..7f65336 100644 --- a/lib/ui/pages/main/talk/talk.dart +++ b/lib/ui/pages/main/talk/talk.dart @@ -4,12 +4,11 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class TalkPage extends StatelessWidget { - TalkPage({Key key}) : super(key: key); @override Widget build(BuildContext context) { - final _roomList = Provider.of(context).roomList; - if (_roomList == null) { - return Center( + final roomList = Provider.of(context).roomList; + if (roomList == null) { + return const Center( child: CircularProgressIndicator(), ); } else { @@ -17,12 +16,12 @@ class TalkPage extends StatelessWidget { physics: ScrollPhysics(), scrollDirection: Axis.vertical, shrinkWrap: true, - itemCount: _roomList.length, + itemCount: roomList.length, itemBuilder: ( BuildContext context, int index, ) { - return TalkPageListTile(_roomList[index]); + return TalkPageListTile(roomList[index]); }, ); } From 1e9cb924395fd67d0403d85f6c84577a220144d3 Mon Sep 17 00:00:00 2001 From: thoth000 Date: Wed, 15 Jul 2020 21:11:54 +0900 Subject: [PATCH 18/20] =?UTF-8?q?=E5=88=A5=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=B8=E3=81=AE=E5=88=87=E3=82=8A=E5=87=BA=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/molecules/home/friend_tile_list.dart | 51 +++++++++ lib/ui/molecules/home/group_tile_list.dart | 49 +++++++++ lib/ui/molecules/home/my_tile.dart | 23 ++++ lib/ui/pages/main/home/home.dart | 116 ++------------------ lib/ui/pages/main/profile/profile.dart | 2 +- lib/ui/pages/main/profile/profile_edit.dart | 4 +- 6 files changed, 136 insertions(+), 109 deletions(-) create mode 100644 lib/ui/molecules/home/friend_tile_list.dart create mode 100644 lib/ui/molecules/home/group_tile_list.dart create mode 100644 lib/ui/molecules/home/my_tile.dart diff --git a/lib/ui/molecules/home/friend_tile_list.dart b/lib/ui/molecules/home/friend_tile_list.dart new file mode 100644 index 0000000..0e58c16 --- /dev/null +++ b/lib/ui/molecules/home/friend_tile_list.dart @@ -0,0 +1,51 @@ +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(context).friendList; + if (friendList == null) { + return const Center( + child: CircularProgressIndicator(), + ); + } else { + return Container( + // ここのラップは適当にサイズ指定しているだけなので、レイアウトに合わせて変更する必要あり + height: 220, + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: AppSpace.small, + ), + ListView.builder( + physics: ScrollPhysics(), + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: friendList.length, + itemBuilder: ( + BuildContext context, + int index, + ) { + return HomePageListTile( + name: friendList[index].name, + imgUrl: friendList[index].imgUrl, + ); + }, + ), + ], + ), + ), + ); + } + } +} diff --git a/lib/ui/molecules/home/group_tile_list.dart b/lib/ui/molecules/home/group_tile_list.dart new file mode 100644 index 0000000..e0fb304 --- /dev/null +++ b/lib/ui/molecules/home/group_tile_list.dart @@ -0,0 +1,49 @@ +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(context).groupList; + if (groupList == null) { + return const Center( + child: CircularProgressIndicator(), + ); + } + return Container( + height: 220, + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: AppSpace.small, + ), + ListView.builder( + physics: ScrollPhysics(), + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: groupList.length, + itemBuilder: ( + BuildContext context, + int index, + ) { + return HomePageListTile( + name: groupList[index].name, + imgUrl: groupList[index].imgUrl, + ); + }, + ), + ], + ), + ), + ); + } +} \ No newline at end of file diff --git a/lib/ui/molecules/home/my_tile.dart b/lib/ui/molecules/home/my_tile.dart new file mode 100644 index 0000000..95d76f5 --- /dev/null +++ b/lib/ui/molecules/home/my_tile.dart @@ -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(context).user; + if (user == null) { + return const Center( + child: CircularProgressIndicator(), + ); + } + return HomePageListTile( + name: user.name, + imgUrl: user.imgUrl, + isMe: true, + ); + } +} \ No newline at end of file diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index 4aba515..0eed47a 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -1,10 +1,13 @@ -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'; import 'package:flutter/material.dart'; + +import 'package:chat_flutter/config/app_space.dart'; + +import 'package:chat_flutter/ui/molecules/home/my_tile.dart'; +import 'package:chat_flutter/ui/molecules/home/friend_tile_list.dart'; +import 'package:chat_flutter/ui/molecules/home/group_tile_list.dart'; + import 'package:chat_flutter/config/app_text_size.dart'; -import 'package:provider/provider.dart'; class HomePage extends StatelessWidget { @override @@ -12,7 +15,7 @@ class HomePage extends StatelessWidget { return SingleChildScrollView( child: Column( children: [ - _MyTile(), + MyTile(), Container( constraints: BoxConstraints( minHeight: MediaQuery.of(context).size.height - 180, @@ -41,7 +44,7 @@ class HomePage extends StatelessWidget { ), ), ), - _GroupTileList(), + GroupTileList(), Divider( endIndent: AppSpace.big, ), @@ -57,7 +60,7 @@ class HomePage extends StatelessWidget { ), ), ), - _FriendTileList(), + FriendTileList(), ], ), ), @@ -66,102 +69,3 @@ class HomePage extends StatelessWidget { ); } } - -class _MyTile extends StatelessWidget { - @override - Widget build(BuildContext context) { - final user = Provider.of(context).user; - if (user == null) { - return const Center( - child: CircularProgressIndicator(), - ); - } - return HomePageListTile( - name: user.name, - imgUrl: user.imgUrl, - isMe: true, - ); - } -} - -class _GroupTileList extends StatelessWidget { - @override - Widget build(BuildContext context) { - final groupList = Provider.of(context).groupList; - if (groupList == null) { - return const Center( - child: CircularProgressIndicator(), - ); - } - return Container( - height: 220, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: AppSpace.small, - ), - ListView.builder( - physics: ScrollPhysics(), - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: groupList.length, - itemBuilder: ( - BuildContext context, - int index, - ) { - return HomePageListTile( - name: groupList[index].name, - imgUrl: groupList[index].imgUrl, - ); - }, - ), - ], - ), - ), - ); - } -} - -class _FriendTileList extends StatelessWidget { - @override - Widget build(BuildContext context) { - final friendList = Provider.of(context).friendList; - if (friendList == null) { - return const Center( - child: CircularProgressIndicator(), - ); - } else { - return Container( - // ここのラップは適当にサイズ指定しているだけなので、レイアウトに合わせて変更する必要あり - height: 220, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: AppSpace.small, - ), - ListView.builder( - physics: ScrollPhysics(), - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: friendList.length, - itemBuilder: ( - BuildContext context, - int index, - ) { - return HomePageListTile( - name: friendList[index].name, - imgUrl: friendList[index].imgUrl, - ); - }, - ), - ], - ), - ), - ); - } - } -} diff --git a/lib/ui/pages/main/profile/profile.dart b/lib/ui/pages/main/profile/profile.dart index 667aae7..497f7d7 100644 --- a/lib/ui/pages/main/profile/profile.dart +++ b/lib/ui/pages/main/profile/profile.dart @@ -51,7 +51,7 @@ class _ProfilePage extends StatelessWidget { child: Container( width: 150, child: RaisedButton.icon( - icon: Icon( + icon: const Icon( Icons.edit, color: Colors.white, ), diff --git a/lib/ui/pages/main/profile/profile_edit.dart b/lib/ui/pages/main/profile/profile_edit.dart index a34bf4a..421cc38 100644 --- a/lib/ui/pages/main/profile/profile_edit.dart +++ b/lib/ui/pages/main/profile/profile_edit.dart @@ -27,7 +27,7 @@ class ProfileEditPage extends StatelessWidget { appBar: ProfilePageAppBar(), backgroundColor: Colors.white, body: (user == null) - ? Center( + ? const Center( child: CircularProgressIndicator(), ) : _ProfileEditPage( @@ -83,7 +83,7 @@ class _ProfileEditPage extends StatelessWidget { child: Container( width: 150, child: RaisedButton.icon( - icon: Icon( + icon: const Icon( Icons.arrow_upward, color: Colors.white, ), From 6b8e56983580d52e69b6ba9e671b1ac0aad30f5c Mon Sep 17 00:00:00 2001 From: thoth000 Date: Wed, 15 Jul 2020 21:12:42 +0900 Subject: [PATCH 19/20] flutter format . --- lib/ui/molecules/home/friend_tile_list.dart | 1 - lib/ui/molecules/home/group_tile_list.dart | 3 +-- lib/ui/molecules/home/my_tile.dart | 2 +- lib/ui/pages/main/home/home.dart | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/ui/molecules/home/friend_tile_list.dart b/lib/ui/molecules/home/friend_tile_list.dart index 0e58c16..0a53c97 100644 --- a/lib/ui/molecules/home/friend_tile_list.dart +++ b/lib/ui/molecules/home/friend_tile_list.dart @@ -7,7 +7,6 @@ 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) { diff --git a/lib/ui/molecules/home/group_tile_list.dart b/lib/ui/molecules/home/group_tile_list.dart index e0fb304..c53366d 100644 --- a/lib/ui/molecules/home/group_tile_list.dart +++ b/lib/ui/molecules/home/group_tile_list.dart @@ -7,7 +7,6 @@ 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) { @@ -46,4 +45,4 @@ class GroupTileList extends StatelessWidget { ), ); } -} \ No newline at end of file +} diff --git a/lib/ui/molecules/home/my_tile.dart b/lib/ui/molecules/home/my_tile.dart index 95d76f5..255c1b0 100644 --- a/lib/ui/molecules/home/my_tile.dart +++ b/lib/ui/molecules/home/my_tile.dart @@ -20,4 +20,4 @@ class MyTile extends StatelessWidget { isMe: true, ); } -} \ No newline at end of file +} diff --git a/lib/ui/pages/main/home/home.dart b/lib/ui/pages/main/home/home.dart index 0eed47a..d7dab04 100644 --- a/lib/ui/pages/main/home/home.dart +++ b/lib/ui/pages/main/home/home.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; - import 'package:chat_flutter/config/app_space.dart'; import 'package:chat_flutter/ui/molecules/home/my_tile.dart'; From 0002225a202e618b012901886ec99a112292c35c Mon Sep 17 00:00:00 2001 From: thoth000 Date: Wed, 15 Jul 2020 21:44:43 +0900 Subject: [PATCH 20/20] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AAaxis.vertical?= =?UTF-8?q?=E3=81=AE=E9=99=A4=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/molecules/home/friend_tile_list.dart | 1 - lib/ui/molecules/home/group_tile_list.dart | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/ui/molecules/home/friend_tile_list.dart b/lib/ui/molecules/home/friend_tile_list.dart index 0a53c97..a2e1385 100644 --- a/lib/ui/molecules/home/friend_tile_list.dart +++ b/lib/ui/molecules/home/friend_tile_list.dart @@ -28,7 +28,6 @@ class FriendTileList extends StatelessWidget { ), ListView.builder( physics: ScrollPhysics(), - scrollDirection: Axis.vertical, shrinkWrap: true, itemCount: friendList.length, itemBuilder: ( diff --git a/lib/ui/molecules/home/group_tile_list.dart b/lib/ui/molecules/home/group_tile_list.dart index c53366d..b37d222 100644 --- a/lib/ui/molecules/home/group_tile_list.dart +++ b/lib/ui/molecules/home/group_tile_list.dart @@ -26,8 +26,7 @@ class GroupTileList extends StatelessWidget { height: AppSpace.small, ), ListView.builder( - physics: ScrollPhysics(), - scrollDirection: Axis.vertical, + physics: const ScrollPhysics(), shrinkWrap: true, itemCount: groupList.length, itemBuilder: (