mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 19:57:42 +01:00
refactor: extract loading widget
This commit is contained in:
parent
15f86d99b1
commit
7d6557d02c
@ -19,6 +19,10 @@ class _HomeState extends State<Home> {
|
||||
icon: Icon(Icons.rss_feed),
|
||||
title: Text('News'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.search),
|
||||
title: Text('Search'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: StreamBuilder<int>(builder: (context, snapshot) {
|
||||
int count = snapshot.data;
|
||||
@ -42,10 +46,6 @@ class _HomeState extends State<Home> {
|
||||
}),
|
||||
title: Text('Notification'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.search),
|
||||
title: Text('Search'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person),
|
||||
title: Text('Me'),
|
||||
@ -58,9 +58,9 @@ class _HomeState extends State<Home> {
|
||||
case 0:
|
||||
return NewsScreen();
|
||||
case 1:
|
||||
return NotificationScreen();
|
||||
case 2:
|
||||
return SearchScreen();
|
||||
case 2:
|
||||
return NotificationScreen();
|
||||
case 3:
|
||||
return ProfileScreen();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import '../providers/settings.dart';
|
||||
import '../widgets/event_item.dart';
|
||||
import '../widgets/loading.dart';
|
||||
import '../utils/utils.dart';
|
||||
|
||||
class NewsScreen extends StatefulWidget {
|
||||
@ -53,6 +54,17 @@ class NewsScreenState extends State<NewsScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildItems(BuildContext context, int index) {
|
||||
// return Loading(more: false);
|
||||
if (_events.length == 0) {
|
||||
return Loading(more: false);
|
||||
} else if (index == _events.length) {
|
||||
return Loading(more: true);
|
||||
} else {
|
||||
return EventItem(_events[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(context) {
|
||||
switch (SettingsProvider.of(context).layout) {
|
||||
@ -66,20 +78,13 @@ class NewsScreenState extends State<NewsScreen> {
|
||||
SliverSafeArea(
|
||||
top: false,
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
if (index == _events.length) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 15),
|
||||
child: CupertinoActivityIndicator(radius: 12),
|
||||
);
|
||||
} else {
|
||||
return EventItem(_events[index]);
|
||||
}
|
||||
},
|
||||
childCount: _events.length + 1,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(_buildItems,
|
||||
childCount: _events.length + 1),
|
||||
),
|
||||
// sliver: SliverList(
|
||||
// delegate:
|
||||
// SliverChildBuilderDelegate(_buildItems, childCount: 1),
|
||||
// ),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -100,16 +105,8 @@ class NewsScreenState extends State<NewsScreen> {
|
||||
child: ListView.builder(
|
||||
controller: _controller,
|
||||
itemCount: _events.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == _events.length) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 15),
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else {
|
||||
return EventItem(_events[index]);
|
||||
}
|
||||
},
|
||||
// itemCount: 1,
|
||||
itemBuilder: _buildItems,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart' hide Notification;
|
||||
import '../providers/settings.dart';
|
||||
import '../screens/screens.dart';
|
||||
import '../widgets/notification_item.dart';
|
||||
import '../widgets/loading.dart';
|
||||
import '../utils/utils.dart';
|
||||
|
||||
class NotificationGroup {
|
||||
@ -116,10 +117,7 @@ class NotificationScreenState extends State<NotificationScreen> {
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
if (index == groups.length) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 15),
|
||||
child: CupertinoActivityIndicator(radius: 12),
|
||||
);
|
||||
return Loading(more: true);
|
||||
} else {
|
||||
return _buildGroupItem(context, index);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import '../widgets/widgets.dart';
|
||||
import '../widgets/loading.dart';
|
||||
|
||||
// Widget of issue screen and pull request screen
|
||||
class IssuePullRequestScreen extends StatefulWidget {
|
||||
@ -39,7 +40,7 @@ class _IssuePullRequestScreenState extends State<IssuePullRequestScreen> {
|
||||
|
||||
Widget _buildBody(BuildContext context) {
|
||||
if (payload == null) {
|
||||
return CupertinoActivityIndicator();
|
||||
return Loading();
|
||||
}
|
||||
|
||||
List items = payload['timeline']['nodes'];
|
||||
|
39
lib/widgets/loading.dart
Normal file
39
lib/widgets/loading.dart
Normal file
@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import '../providers/settings.dart';
|
||||
|
||||
class Loading extends StatelessWidget {
|
||||
final bool more;
|
||||
|
||||
Loading({this.more});
|
||||
|
||||
Widget _buildIndicator(BuildContext context) {
|
||||
switch (SettingsProvider.of(context).layout) {
|
||||
case LayoutMap.cupertino:
|
||||
return CupertinoActivityIndicator(radius: 12);
|
||||
default:
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (more) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 20),
|
||||
child: _buildIndicator(context),
|
||||
);
|
||||
} else {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 40),
|
||||
child: _buildIndicator(context),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user