2019-09-24 13:58:34 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-09-25 11:06:36 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2019-09-24 13:58:34 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-10-02 08:58:11 +02:00
|
|
|
import 'package:git_touch/scaffolds/common.dart';
|
2019-09-25 11:06:36 +02:00
|
|
|
import 'package:git_touch/scaffolds/utils.dart';
|
2019-09-24 13:58:34 +02:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2019-09-25 11:06:36 +02:00
|
|
|
class TabScaffold extends StatelessWidget {
|
|
|
|
final Widget title;
|
|
|
|
final Widget body;
|
2019-10-03 04:01:54 +02:00
|
|
|
final Widget action;
|
2019-09-25 11:06:36 +02:00
|
|
|
final void Function() onRefresh;
|
2019-09-25 12:47:34 +02:00
|
|
|
final List<String> tabs;
|
|
|
|
final int activeTab;
|
|
|
|
final Function(int index) onTabSwitch;
|
2019-09-24 13:58:34 +02:00
|
|
|
|
|
|
|
TabScaffold({
|
|
|
|
@required this.title,
|
2019-09-25 11:06:36 +02:00
|
|
|
@required this.body,
|
2019-10-03 04:01:54 +02:00
|
|
|
this.action,
|
2019-09-24 13:58:34 +02:00
|
|
|
@required this.onRefresh,
|
2019-09-25 12:47:34 +02:00
|
|
|
@required this.tabs,
|
|
|
|
@required this.activeTab,
|
|
|
|
@required this.onTabSwitch,
|
2019-09-24 13:58:34 +02:00
|
|
|
});
|
|
|
|
|
2019-09-25 11:06:36 +02:00
|
|
|
Widget _buildTitle(BuildContext context) {
|
|
|
|
switch (Provider.of<ThemeModel>(context).theme) {
|
|
|
|
case AppThemeType.cupertino:
|
|
|
|
return DefaultTextStyle(
|
2019-09-27 15:39:36 +02:00
|
|
|
style: TextStyle(fontSize: 14),
|
2019-09-25 11:06:36 +02:00
|
|
|
child: CupertinoSegmentedControl(
|
2019-09-25 12:47:34 +02:00
|
|
|
groupValue: activeTab,
|
|
|
|
onValueChanged: onTabSwitch,
|
|
|
|
children: tabs.asMap().map((key, text) => MapEntry(
|
2019-09-25 11:06:36 +02:00
|
|
|
key,
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
child: Text(text),
|
|
|
|
))),
|
|
|
|
),
|
|
|
|
);
|
2019-09-24 14:35:37 +02:00
|
|
|
default:
|
2019-09-25 11:06:36 +02:00
|
|
|
return title;
|
2019-09-24 14:35:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 13:58:34 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-09-25 11:06:36 +02:00
|
|
|
final scaffold = CommonScaffold(
|
|
|
|
title: _buildTitle(context),
|
|
|
|
body: RefreshWrapper(body: body, onRefresh: onRefresh),
|
2019-10-03 04:01:54 +02:00
|
|
|
action: action,
|
2019-09-25 11:06:36 +02:00
|
|
|
bottom: TabBar(
|
2019-09-25 12:47:34 +02:00
|
|
|
onTap: onTabSwitch,
|
|
|
|
tabs: tabs.map((text) => Tab(text: text.toUpperCase())).toList(),
|
2019-09-25 11:06:36 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2019-09-24 13:58:34 +02:00
|
|
|
switch (Provider.of<ThemeModel>(context).theme) {
|
|
|
|
case AppThemeType.cupertino:
|
2019-09-25 11:06:36 +02:00
|
|
|
return scaffold;
|
2019-09-24 13:58:34 +02:00
|
|
|
default:
|
|
|
|
return DefaultTabController(
|
2019-09-25 12:47:34 +02:00
|
|
|
length: tabs.length,
|
2019-09-25 11:06:36 +02:00
|
|
|
child: scaffold,
|
2019-09-24 13:58:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|