1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-02 08:56:54 +01:00

80 lines
2.2 KiB
Dart
Raw Normal View History

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