hmg wifi implementation 1.0
parent
f4100a138d
commit
62c3c47fe9
@ -1,50 +1,115 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mohem_flutter_app/classes/colors.dart';
|
||||
import 'package:mohem_flutter_app/classes/utils.dart';
|
||||
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
|
||||
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
|
||||
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
|
||||
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
|
||||
import 'package:mohem_flutter_app/provider/hmg_connection_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
class HmgConnectivityButton extends StatefulWidget {
|
||||
const HmgConnectivityButton({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<HmgConnectivityButton> createState() => _HmgConnectivityButtonState();
|
||||
}
|
||||
|
||||
class _HmgConnectivityButtonState extends State<HmgConnectivityButton> with SingleTickerProviderStateMixin {
|
||||
|
||||
|
||||
late Animation<Color?> animation;
|
||||
late AnimationController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 1500),
|
||||
vsync: this,
|
||||
);
|
||||
CurvedAnimation curve = CurvedAnimation(parent: controller, curve: Curves.linear);
|
||||
animation = ColorTween(begin: Colors.transparent, end:MyColors.gradiantStartColor).animate(curve);
|
||||
|
||||
animation.addStatusListener((status) {
|
||||
if (status == AnimationStatus.completed) {
|
||||
controller.reverse();
|
||||
} else if (status == AnimationStatus.dismissed) {
|
||||
controller.forward();
|
||||
}
|
||||
setState(() {});
|
||||
});
|
||||
controller.forward();
|
||||
}
|
||||
|
||||
class HmgConnectivityButton extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Provider.of<HmgConnectionProvider>(context, listen: false).checkHmgNetworkConnectivity();
|
||||
return Consumer<HmgConnectionProvider>(
|
||||
builder: (_, HmgConnectionProvider foo, __) {
|
||||
return Container(
|
||||
height: 45,
|
||||
padding: const EdgeInsets.only(left: 12, right: 12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(200.0),
|
||||
gradient: const LinearGradient(
|
||||
transform: GradientRotation(.83),
|
||||
begin: Alignment.topRight,
|
||||
end: Alignment.bottomLeft,
|
||||
colors: <Color>[
|
||||
MyColors.gradiantEndColor,
|
||||
MyColors.gradiantStartColor,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: (){
|
||||
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.wifi,
|
||||
color: Colors.white,
|
||||
),
|
||||
12.width,
|
||||
LocaleKeys.connectHmgWifi.tr().toText18(color: Colors.white),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
// Provider.of<HmgConnectionProvider>(context, listen: false).checkHmgNetworkConnectivity();
|
||||
return Row(
|
||||
children: [
|
||||
Consumer<HmgConnectionProvider>(
|
||||
builder: (_, HmgConnectionProvider provider, __) {
|
||||
return AnimatedBuilder(
|
||||
animation: animation,
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return Container(
|
||||
height: 45,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(200.0),
|
||||
gradient: const LinearGradient(
|
||||
transform: GradientRotation(.83),
|
||||
begin: Alignment.topRight,
|
||||
end: Alignment.bottomLeft,
|
||||
colors: <Color>[
|
||||
MyColors.gradiantEndColor,
|
||||
MyColors.gradiantStartColor,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(left: 12, right: 12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(200.0),
|
||||
color: animation.value,
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
if (provider.isConnectedToHMG) {
|
||||
Utils.showLoading(context);
|
||||
await provider.closeWifiRequest();
|
||||
Utils.hideLoading(context);
|
||||
} else {
|
||||
Utils.showLoading(context);
|
||||
await provider.connectWithHmgNetwork();
|
||||
Utils.hideLoading(context);
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.wifi,
|
||||
color: provider.isConnectedToHMG ? Colors.white : Colors.grey[700],
|
||||
size: 16,
|
||||
),
|
||||
8.width,
|
||||
provider.isConnectedToHMG ? LocaleKeys.connectedHmgWifi.tr().toText12(color: Colors.white) : LocaleKeys.connectHmgWifi.tr().toText12(color: Colors.white),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue