Skip to content

Commit

Permalink
Consolidate WifiPage in ConnectionsPage (#165)
Browse files Browse the repository at this point in the history
* Consolidate WifiPage in ConnectionsPage

* Hierachy fix and light theme fix

* Styling changes

* write Wi-Fi correctly

* Limit the width of the tabbar

* Move wifi to it's own file
  • Loading branch information
Feichtmeier authored Nov 13, 2021
1 parent f2b0cc5 commit 2f75b35
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 42 deletions.
84 changes: 84 additions & 0 deletions lib/view/pages/connections/connections_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'package:flutter/material.dart';
import 'package:nm/nm.dart';
import 'package:provider/provider.dart';
import 'package:settings/view/pages/connections/wifi_content.dart';
import 'package:yaru_icons/widgets/yaru_icons.dart';

import 'models/wifi_model.dart';

class ConnectionsPage extends StatefulWidget {
static Widget create(BuildContext context) {
final service = Provider.of<NetworkManagerClient>(context, listen: false);
return ChangeNotifierProvider<WifiModel>(
create: (_) => WifiModel(service),
child: const ConnectionsPage(),
);
}

const ConnectionsPage({Key? key}) : super(key: key);

@override
State<ConnectionsPage> createState() => _ConnectionsPageState();
}

class _ConnectionsPageState extends State<ConnectionsPage>
with TickerProviderStateMixin {
late TabController tabController;

@override
void initState() {
tabController = TabController(length: 3, vsync: this);
super.initState();
}

@override
Widget build(BuildContext context) {
final wifiModel = context.watch<WifiModel>();
return Column(
children: [
Container(
width: 516,
height: 60,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(4)),
child: TabBar(
controller: tabController,
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color:
Theme.of(context).colorScheme.onSurface.withOpacity(0.1)),
tabs: const [
Tab(
icon: Icon(YaruIcons.network_wireless),
child: Text("Wi-Fi")),
Tab(
icon: Icon(YaruIcons.network_wired),
child: Text("Ethernet")),
Tab(
icon: Icon(YaruIcons.call_incoming),
child: Text("Cellular")),
]),
),
Padding(
padding: const EdgeInsets.only(top: 30),
child: SizedBox(
height: 1000,
child: TabBarView(
controller: tabController,
children: [
wifiModel.isWifiDeviceAvailable
? const WifiDevicesContent()
: const WifiAdaptorNotFound(),
Column(
children: const [Text('Ethernet')],
),
Column(
children: const [Text('Cellular')],
)
],
),
),
),
],
);
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ class AccessPointTile extends StatelessWidget {
borderRadius: BorderRadius.circular(4),
onTap: onTap,
child: YaruRow(
trailingWidget: Text(accessPointModel.name),
leadingWidget: Icon(accessPointModel.wifiIconData),
trailingWidget: Row(
children: [
Icon(accessPointModel.wifiIconData),
const SizedBox(
width: 10,
),
Text(accessPointModel.name),
],
),
actionWidget: Row(
children: [
Icon(accessPointModel.isActiveIconData),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:nm/nm.dart';
import 'package:provider/provider.dart';
import 'package:yaru_icons/widgets/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';
Expand All @@ -9,48 +8,39 @@ import 'models/wifi_model.dart';
import 'widgets/access_point_tile.dart';
import 'widgets/authentication_dialog.dart';

class WifiPage extends StatelessWidget {
static Widget create(BuildContext context) {
final service = Provider.of<NetworkManagerClient>(context, listen: false);
return ChangeNotifierProvider<WifiModel>(
create: (_) => WifiModel(service),
child: const WifiPage(),
);
}

const WifiPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final wifiModel = context.watch<WifiModel>();
if (wifiModel.isWifiDeviceAvailable) return const _WifiDevicesContent();
return const _WifiAdaptorNotFound();
}
}

class _WifiDevicesContent extends StatelessWidget {
const _WifiDevicesContent({Key? key}) : super(key: key);
class WifiDevicesContent extends StatelessWidget {
const WifiDevicesContent({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final wifiModel = context.watch<WifiModel>();

return Column(
children: [
YaruSwitchRow(
trailingWidget: const Text('Wifi'),
actionDescription:
wifiModel.isWifiEnabled ? 'connected' : 'disconnected',
onChanged: (newValue) => wifiModel.toggleWifi(newValue),
value: wifiModel.isWifiEnabled,
),
YaruRow(
trailingWidget: const Text('Wi-Fi'),
actionWidget: Row(
children: [
Text(
wifiModel.isWifiEnabled ? 'connected' : 'disconnected',
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.5)),
),
Switch(
onChanged: (newValue) => wifiModel.toggleWifi(newValue),
value: wifiModel.isWifiEnabled),
],
)),
if (wifiModel.isWifiEnabled)
for (final wifiDevice in wifiModel.wifiDevices)
AnimatedBuilder(
animation: wifiDevice,
builder: (_, __) {
return YaruSection(
headline: wifiDevice.interface,
headline: 'Visible Networks',
children: [
for (final accessPoint in wifiDevice.accesPoints)
AccessPointTile(
Expand Down Expand Up @@ -85,8 +75,8 @@ class _WifiDevicesContent extends StatelessWidget {
}
}

class _WifiAdaptorNotFound extends StatelessWidget {
const _WifiAdaptorNotFound({Key? key}) : super(key: key);
class WifiAdaptorNotFound extends StatelessWidget {
const WifiAdaptorNotFound({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand Down
11 changes: 3 additions & 8 deletions lib/view/pages/page_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@ import 'package:settings/view/pages/notifications/notifications_page.dart';
import 'package:settings/view/pages/power/power_page.dart';
import 'package:settings/view/pages/sound/sound_page.dart';
import 'package:settings/view/pages/wallpaper/wallpaper_page.dart';
import 'package:settings/view/pages/wifi/wifi_page.dart';
import 'package:settings/view/pages/connections/connections_page.dart';
import 'package:yaru_icons/widgets/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

final pageItems = <YaruPageItem>[
const YaruPageItem(
title: 'WIFI',
iconData: YaruIcons.network_wireless,
builder: WifiPage.create,
),
YaruPageItem(
title: 'Network',
title: 'Connections',
iconData: YaruIcons.network,
builder: (_) => const Text('Network'),
builder: ConnectionsPage.create,
),
YaruPageItem(
title: 'Bluetooth',
Expand Down

0 comments on commit 2f75b35

Please sign in to comment.