1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-16 10:20:55 +01:00
git-touch-android-ios-app/lib/scaffolds/tab.dart

70 lines
1.9 KiB
Dart
Raw Normal View History

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-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;
final Widget trailing;
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,
this.trailing,
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(
style: TextStyle(fontSize: 16),
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),
trailing: trailing,
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
);
}
}
}