| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 3 | import 'package:cake_wallet/generated/i18n.dart'; |
| 4 | import 'package:cake_wallet/src/screens/base_page.dart'; |
| 5 | import 'package:cake_wallet/src/widgets/primary_button.dart'; |
| 6 | import 'package:cake_wallet/view_model/start_tor_view_model.dart'; |
| 7 | |
| 8 | class StartTorPage extends BasePage { |
| 9 | StartTorPage(this.startTorViewModel); |
| 10 | |
| 11 | final StartTorViewModel startTorViewModel; |
| 12 | |
| 13 | @override |
| 14 | String get title => S.current.tor_connection; |
| 15 | |
| 16 | @override |
| 17 | Widget leading(BuildContext context) { |
| 18 | return Container(); |
| 19 | } |
| 20 | |
| 21 | @override |
| 22 | Widget body(BuildContext context) { |
| 23 | startTorViewModel.startTor(context); |
| 24 | return Container( |
| 25 | padding: EdgeInsets.all(24), |
| 26 | child: Column( |
| 27 | mainAxisAlignment: MainAxisAlignment.center, |
| 28 | crossAxisAlignment: CrossAxisAlignment.center, |
| 29 | children: [ |
| 30 | Column( |
| 31 | children: [ |
| 32 | SizedBox(width: double.maxFinite), |
| 33 | if (startTorViewModel.isLoading) ...[ |
| 34 | CircularProgressIndicator(), |
| 35 | SizedBox(height: 20), |
| 36 | _buildWaitingText(context), |
| 37 | ], |
| 38 | if (startTorViewModel.showOptions) ...[ |
| 39 | _buildOptionsButtons(context), |
| 40 | ], |
| 41 | ], |
| 42 | ), |
| 43 | ], |
| 44 | ), |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | Widget _buildWaitingText(BuildContext context) { |
| 49 | return Observer( |
| 50 | builder: (_) { |
| 51 | return Column( |
| 52 | children: [ |
| 53 | Text( |
| 54 | S.current.establishing_tor_connection, |
| 55 | style: TextStyle( |
| 56 | fontSize: 16, |
| 57 | fontWeight: FontWeight.bold, |
| 58 | ), |
| 59 | textAlign: TextAlign.center, |
| 60 | ), |
| 61 | if (startTorViewModel.showOptions) _buildOptionsButtons(context), |
| 62 | ], |
| 63 | ); |
| 64 | }, |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | Widget _buildOptionsButtons(BuildContext context) { |
| 69 | return Column( |
| 70 | children: [ |
| 71 | Text( |
| 72 | S.current.tor_connection_timeout, |
| 73 | style: TextStyle( |
| 74 | fontSize: 16, |
| 75 | fontWeight: FontWeight.bold, |
| 76 | ), |
| 77 | textAlign: TextAlign.center, |
| 78 | ), |
| 79 | SizedBox(height: 24), |
| 80 | PrimaryButton( |
| 81 | onPressed: () => startTorViewModel.disableTor(context), |
| 82 | text: S.current.disable_tor, |
| 83 | color: Theme.of(context).colorScheme.primary, |
| 84 | textColor: Colors.white, |
| 85 | ), |
| 86 | SizedBox(height: 16), |
| 87 | PrimaryButton( |
| 88 | onPressed: () => startTorViewModel.ignoreAndLaunchApp(context), |
| 89 | text: S.current.ignor, |
| 90 | color: Theme.of(context).colorScheme.secondary, |
| 91 | textColor: Colors.white, |
| 92 | ), |
| 93 | ], |
| 94 | ); |
| 95 | } |
| 96 | } |